SELECT DATEDIFF_GRP,ROUND(COUNT(DISTINCT(ORDER_ID))*100/(SELECT COUNT(DISTINCT(A.ORDER_ID)) FROM A),2)||'%' AS PERCENTAGE_ORDERS FROM A
GROUP BY DATEDIFF_GRP ;
WITH A AS (SELECT OS.ACTUAL_DISPATCH_DATE,OT.ORDER_ID,OT.First_msg_date,datediff(OT.First_msg_date,OS.ACTUAL_DISPATCH_DATE) AS DATEDIFF,
CASE WHEN datediff(OT.First_msg_date,OS.ACTUAL_DISPATCH_DATE)<=0 THEN 'OTIF'
WHEN datediff(OT.First_msg_date,OS.ACTUAL_DISPATCH_DATE)=1 THEN 'OTIF+1'
WHEN datediff(OT.First_msg_date,OS.ACTUAL_DISPATCH_DATE)=2 THEN 'OTIF+2'
ELSE 'OTIF+>2'
END as DATEDIFF_GRP
FROM order_shipment OS RIGHT JOIN
(SELECT ORDER_ID,MIN((str_to_date(SUBSTRING(MESSAGE,INSTR(MESSAGE,'2'),10),'%Y-%m-%d'))) AS First_msg_date
FROM ORDER_TIMELINE
GROUP BY ORDER_ID ) OT
ON (OS.ORDER_ID=OT.ORDER_ID))
SELECT DATEDIFF_GRP,concat(ROUND(COUNT(DISTINCT(ORDER_ID))*100/(SELECT COUNT(DISTINCT(A.ORDER_ID)) FROM A),2),'%') AS PERCENTAGE_ORDERS
FROM A
GROUP BY DATEDIFF_GRP ;
2条答案
按热度按时间flmtquvp1#
你可以在下面试试-在我看来,你是想用
||
运营商mysql支持concat()
功能不可用||
操作人员2g32fytz2#
mysql通常不使用
||
对于字符串连接,您必须启用一些非默认选项才能获得此结果。现在的情况是mysql正在解释
||
作为逻辑OR
接线员。要完全避免此问题,请考虑使用CONCAT
功能。您还可以通过启用
ANSI
但是正如下面的评论,很少有mysql用户在这种模式下使用数据库。