我有这样的疑问
select
REPLACE(REPLACE(REPLACE(LEFT(createdtime,10),'-',''),':',''),'T','') as paydate,
SUM(CASE WHEN status='SUCCESS' AND issync='1' then 1 ELSE 0 END) as sumpaid,
SUM(CASE WHEN status='SUCCESS' AND issync in ('3','4') then 1 ELSE 0 END) as sumfail,
SUM(CASE WHEN status='CLOSED' then 1 ELSE 0 END) as sumclose,
SUM(CASE WHEN status='NULL' then 1 ELSE 0 END) as sumunflag
from
tb_r_orderdata
WHERE
tb_r_orderdata.createdtime IS NOT NULL
group by
tb_r_orderdata.createdtime
ORDER by
tb_r_orderdata.createdtime ASC
在输出中,我想要
20170725 7 3 4 3
20170726 5 6 2 4
最佳答案
以替换您的群并按付款日期订购?
select
REPLACE(REPLACE(REPLACE(LEFT(createdtime,10),'-',''),':',''),'T','') as paydate,
SUM(CASE WHEN status='SUCCESS' AND issync='1' then 1 ELSE 0 END) as sumpaid,
SUM(CASE WHEN status='SUCCESS' AND issync in ('3','4') then 1 ELSE 0 END) as sumfail,
SUM(CASE WHEN status='CLOSED' then 1 ELSE 0 END) as sumclose,
SUM(CASE WHEN status='NULL' then 1 ELSE 0 END) as sumunflag
from
tb_r_orderdata
WHERE
tb_r_orderdata.createdtime IS NOT NULL
group by
paydate
ORDER by
paydate ASC
关于mysql - 如何用mysql计数每一小时到一天,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47195608/