mysql 按照小时去除一段时间内的不同状态数据统计

 1 SELECT
 2     HOUR (时间) AS HOUR,
 3     COUNT(
 4         CASE
 5         WHEN orderlist.State = 1 THEN
 6             orderlist.State
 7         END
 8     ) AS suCount,
 9     COUNT(
10         CASE
11         WHEN orderlist.State = 0 THEN
12             orderlist.State
13         END
14     ) AS failCount,
15     数据列,
16    数据列,
17    数据列
18 FROM
19     orderlist
20 WHERE
21     时间 BETWEEN '开始时间'
22 AND '结束时间'
23 GROUP BY
24     HOUR (时间)
25 ORDER BY
26     HOUR (时间)
时间格式:yyyy-MM-dd HH:mm:ss
posted @ 2018-12-24 11:41  sanpi1992  阅读(562)  评论(0编辑  收藏  举报