SQL Query to return 24 hour, hourly count even when no values exist?

前端 未结 6 1357
-上瘾入骨i
-上瘾入骨i 2021-01-14 08:53

I\'ve written a query that groups the number of rows per hour, based on a given date range.

SELECT CONVERT(VARCHAR(8),TransactionTime,101) + \' \' + CONVERT(         


        
6条回答
  •  广开言路
    2021-01-14 09:40

    You have just discovered the value of the NUMBERS table. You need to create a table with a single column containing the numbers 0 to 23 in it. Then you join again this table using an OUTER join to ensure you always get 24 rows returned.

提交回复
热议问题