oracle SQL GROUP BY 周(周一 07:00:00 至周一 06:59:59)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1067315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL GROUP BY week (Monday 07:00:00 to Monday 06:59:59)
提问by Jeffrey Kemp
I've created a query that groups production data on ISO week by using this query
我创建了一个查询,通过使用此查询对 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')
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.
问题是我们的“生产周”没有遵循 ISO 标准。它们从星期一早上 07:00:00 运行到星期一早上 06:59:59。
Any suggestions on how I can get it to report using our production weeks?
关于如何使用我们的生产周进行报告的任何建议?
Thanks kindly,
好心谢谢
Tommy
汤米
回答by Jeffrey Kemp
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')