Leighton21
Technical User
Hi all,
I have the following table (including data)
Date Product PrevProd Weight
12/06/2008 4:15:00 AM A A 100
12/06/2008 4:30:00 AM B A 100
12/06/2008 5:00:00 AM B B 100
12/06/2008 5:30:00 AM B B 100
12/06/2008 5:45:00 AM B B 100
I am trying to query the data so that it is grouped hourly. But as an added twist the data needs to account for change in the product. This sounds simple however that data needs to come out like the following
Date Product Weight
12/06/2008 4:30:00 AM A 200
12/06/2008 5:00:00 AM B 100
12/06/2008 6:00:00 AM B 200
So you can see that it needs to be grouped by previous product. It then needs to be grouped by the hour but if there is a change of product the Date needs to be the date time of when the product changed. Therefore anything from
05:00:00:001 to 06:00:00:000 is summed and put against the 06:00 time slot. Anything from 04:00:00:001 to the 04:30 (the change in product) is summed against the 04:30 time slot. Everthing after the 04:30 (product change is summed and placed against the 05:00 time slot.
Essentially i have grouped by the rounded hour to get and then by previous product
Date Product Weight
12/06/2008 5:00:00 AM A 200
12/06/2008 5:00:00 AM B 400
12/06/2008 6:00:00 AM B 200
But I cant figure out how to select the 4:30 as the time instead of the 5:00:00 AM
Cheers
I have the following table (including data)
Date Product PrevProd Weight
12/06/2008 4:15:00 AM A A 100
12/06/2008 4:30:00 AM B A 100
12/06/2008 5:00:00 AM B B 100
12/06/2008 5:30:00 AM B B 100
12/06/2008 5:45:00 AM B B 100
I am trying to query the data so that it is grouped hourly. But as an added twist the data needs to account for change in the product. This sounds simple however that data needs to come out like the following
Date Product Weight
12/06/2008 4:30:00 AM A 200
12/06/2008 5:00:00 AM B 100
12/06/2008 6:00:00 AM B 200
So you can see that it needs to be grouped by previous product. It then needs to be grouped by the hour but if there is a change of product the Date needs to be the date time of when the product changed. Therefore anything from
05:00:00:001 to 06:00:00:000 is summed and put against the 06:00 time slot. Anything from 04:00:00:001 to the 04:30 (the change in product) is summed against the 04:30 time slot. Everthing after the 04:30 (product change is summed and placed against the 05:00 time slot.
Essentially i have grouped by the rounded hour to get and then by previous product
Date Product Weight
12/06/2008 5:00:00 AM A 200
12/06/2008 5:00:00 AM B 400
12/06/2008 6:00:00 AM B 200
But I cant figure out how to select the 4:30 as the time instead of the 5:00:00 AM
Cheers