WITH tests([time],title) AS ( SELECT '2016-03-22 1:12:00','a' UNION ALL SELECT '2016-03-22 2:12:00','b' UNION ALL SELECT '2016-03-22 9:12:00','c' ) select sv.number ,count(title) FROM master..spt_values AS sv LEFT JOIN tests AS t ON sv.number=DATEPART(hh,t.[time]) WHERE sv.type='P' and sv.number BETWEEN 0 AND 24 group by CONVERT(varchar,[time],102), sv.number
(21条消息) SQL SERVER 统计24小时内每小时添加的数据-大数据-CSDN问答
标签:24,03,00,22,number,sv,SQL,SERVER From: https://www.cnblogs.com/okeyl/p/17175891.html