使用SQL [mysql]按天收集

时间:2015-09-12 19:41:13

标签: mysql sql

我的表格如下:

datePickup           deliveryStatus    count 
2015-09-04 16:14:55  1                 NULL
2015-09-04 15:52:52  99                NULL
2015-09-04 12:47:55  2                 NULL
2015-09-05 06:14:55  99                NULL
2015-09-05 15:52:52  99                NULL
2015-09-05 17:47:55  99                NULL
2015-09-06 02:14:55  1                 NULL
2015-09-06 14:52:52  99                NULL
2015-09-06 17:47:55  99                NULL

如果交货状态为99,我希望白天完成交货:

datePickup   count 
2015-09-04   1     
2015-09-05   3     
2015-09-06   2                 

2 个答案:

答案 0 :(得分:1)

GROUP BYDATE()

一起使用
SELECT DATE(datePickup), count(*)
FROM yourtable
WHERE deliveryStatus=99
GROUP BY DATE(datePickup);

答案 1 :(得分:0)

尝试DATE_FORMAT

select DATE_FORMAT(datePickup, '%Y-%m-%d'), count(*) where deliveryStatus = 99 group by DATE_FORMAT(datePickup, '%Y-%m-%d')