在我的应用程序中,我只想得到number of sales in a day by diiferent time interval
像
-----------------------------------------------------
Interval | Count
-----------------------------------------------------
00:30 to 0:130 | 3
01:30 to 10:30 | 4
02:30 to 03:30 | 5
..
..
12:30 to 00:30 | 10
-----------------------------------------------------
我尝试了如下查询
select '00:30 to 01:30' as intrval , COUNT(*) AS 'count' from Pharmacy.tblSalesHdr SH
where CAST(SH.created_Date AS TIME) BETWEEN '00:30' AND '00:30'
UNION ALL
select '01:30 to 02:30' as intrval , COUNT(*) AS 'count' from Pharmacy.tblSalesHdr SH
where CAST(SH.created_Date AS TIME) BETWEEN '01:30' AND '02:30'
UNION ALL
select '02:30 to 03:30' as intrval , COUNT(*) AS 'count' from Pharmacy.tblSalesHdr SH
where CAST(SH.created_Date AS TIME) BETWEEN '02:30' AND '03:30'
and so on...
我只是想知道是否有任何better and optimized method
实现这一目标。如果有人知道请分享。