I am doing a query in the bank, to return the product entry by hour (from 00:00 to 23:00) during a certain day; follows the query:
SELECT CONVERT(VARCHAR(13),DATA_ENTRADA,120)+ ':00:00' AS HORA,COUNT(*) AS QTD
FROM Tb_Produtos
GROUP BY CONVERT(VARCHAR(13),DATA_ENTRADA,120)+ ':00:00'
ORDER BY CONVERT(VARCHAR(13),DATA_ENTRADA,120)+ ':00:00';
This query shows me only the quantities in the times that I have registered; follows the return:
HORA / QTD
2017-01-01 00:00:00 / 4
2017-01-01 06:00:00 / 2
2017-01-01 07:00:00 / 2
2017-01-01 08:00:00 / 3
2017-01-01 10:00:00 / 1
2017-01-01 12:00:00 / 22
2017-01-01 13:00:00 / 24
2017-01-01 14:00:00 / 43
2017-01-01 15:00:00 / 22
2017-01-01 16:00:00 / 27
2017-01-01 17:00:00 / 18
2017-01-01 18:00:00 / 17
2017-01-01 19:00:00 / 23
2017-01-01 20:00:00 / 28
2017-01-01 21:00:00 / 46
2017-01-01 22:00:00 / 18
2017-01-01 23:00:00 / 10
Is it possible to return an amount 0 at a time when it does not have any records?
Ex: TIME / QTD
2017-01-01 00:00:00 / 4
2017-01-01 01:00:00 / 0
2017-01-01 02:00:00 / 0
2017-01-01 03:00:00 / 0
2017-01-01 04:00:00 / 0
2017-01-01 05:00:00 / 0
2017-01-01 06:00:00 / 2
2017-01-01 07:00:00 / 2
2017-01-01 08:00:00 / 3
2017-01-01 10:00:00 / 1
2017-01-01 11:00:00 / 0
2017-01-01 12:00:00 / 22
2017-01-01 13:00:00 / 24
2017-01-01 14:00:00 / 43
2017-01-01 15:00:00 / 22
2017-01-01 16:00:00 / 27
2017-01-01 17:00:00 / 18
2017-01-01 18:00:00 / 17
2017-01-01 19:00:00 / 23
2017-01-01 20:00:00 / 28
2017-01-01 21:00:00 / 46
2017-01-01 22:00:00 / 18
2017-01-01 23:00:00 / 10
Thank you in advance