0
I am making an appointment at the bank, to return the entry of products per hour (from 00:00 until 23:00) during a given day; follow the consultation:
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 I have record; follow 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
You can return a quantity of 0 at the time when you have no record?
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
Thanks in advance
Production should be accounted for per day/hour or only per hour?
– José Diz
Could create the table structure and the Insert, for us to try to help
– Tiedt Tech