SQL GROUP BY周(周一07:00:00至周一06:59:59)

时间:2009-07-01 04:48:09

标签: sql oracle datetime

我创建了一个查询,通过使用此查询

对ISO周的生产数据进行分组
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')

问题是我们的“生产周”不符合ISO标准。他们从周一早上07:00:00到周一早上06:59:59。

有关如何使用我们的制作周报告的建议吗?

谢天谢地,

托米

1 个答案:

答案 0 :(得分:6)

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')