views:

1294

answers:

1

Hi folks,

I've created a query that groups production data on ISO week by using this query

SELECT to_char(wid_date,'IYYY'), to_char(wid_date,'IW'), tonnes
FROM production
WHERE to_char(wid_date,'IYYY') = '2009' 
GROUP BY to_char(wid_date,'IYYY'), to_char(wid_date,'IW')

The problem is that our "production weeks" don't follow the ISO standard. They run from Monday morning at 07:00:00 to Monday morning at 06:59:59.

Any suggestions on how I can get it to report using our production weeks?

Thanks kindly,

Tommy

+2  A: 
SELECT to_char(wid_date - 7/24,'IYYY'), to_char(wid_date - 7/24,'IW'), tonnes
FROM production
WHERE to_char(wid_date - 7/24,'IYYY') = '2009' 
GROUP BY to_char(wid_date - 7/24,'IYYY'), to_char(wid_date - 7/24,'IW')
Jeffrey Kemp
wow. that worked like a charm. i can't believe it's as clean as it is.
thanks so much!
Corrected my code (boundary condition). The year grouping has to be adjusted in the same way. Otherwise you'll hit a bug in 2012/13, 2018/19, 2024/25, as well as when working with data in years such as 2001/02, and 2007/08...
Jeffrey Kemp