sql server - Grouping/aggregating SQL results into 1-hour buckets -
Similarly, I need to record a large number of "buckets" in 1 hour. For example, suppose I have a specific order table with the detrite attached to each order, and I want to see the total number of orders per hour. Therefore, I am using SQL in this way:
Datapter (HH, order_date) of order group from date (hh, order_date), sum (order_id)
The problem is that if there is no order in the given 1 hour "bucket", then there is no row in the result line. I want a line for every 24 hours as a result, but if no order has been made during any particular time, then simply record the number of orders as o.
Is there any way in this one question?
Also see.
You get a pre-populated table (or the result of joining a table by a function), in which Your results will be all 1-hour slots.
Then you make an additional participant with it, and you will be able to attach a number of additional couples to DATEPART (hh, Order_date) = SLOT_HOUR by SLOT_HOUR group
Comments
Post a Comment