如何用mysql计算每小时到一天

时间:2017-11-09 06:50:10

标签: mysql

我有这样的查询

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

enter image description here

在输出中我想要像

这样的东西
20170725 7 3 4 3 
20170726 5 6 2 4 

1 个答案:

答案 0 :(得分:1)

更换您的论坛并按订单更改?

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
相关问题