Oracle SQL:前 X 个等周 () 的查询结果(其中 X 可能 > 52)
我如何调整此查询以显示之前(例如 61 周)?
select
to_char(order_date,'IYYY') as iso_year,
to_char(order_date,'IW') as iso_week,
sum(sale_amount)
from orders
where
to_char(order_date,'IW') <> to_char(SYSDATE) --exclude this week in progress
and to_char(order_date,'IYYY') = 2010
group by
to_char(order_date,'IYYY')
to_char(order_date,'IW')
我的第一反应是
where
to_char(order_date,'IW') <> to_char(SYSDATE) --exclude this week in progress
and to_char(order_date,'IYYY') >= to_char(order_date,'IW') - 61
我可以省略“2010”要求并将结果限制为 61 行吗?有更好的办法吗?
非常感谢任何帮助我指明正确方向的帮助!
How could I adapt this query to show the previous, say, 61 weeks?
select
to_char(order_date,'IYYY') as iso_year,
to_char(order_date,'IW') as iso_week,
sum(sale_amount)
from orders
where
to_char(order_date,'IW') <> to_char(SYSDATE) --exclude this week in progress
and to_char(order_date,'IYYY') = 2010
group by
to_char(order_date,'IYYY')
to_char(order_date,'IW')
My first instinct is to do
where
to_char(order_date,'IW') <> to_char(SYSDATE) --exclude this week in progress
and to_char(order_date,'IYYY') >= to_char(order_date,'IW') - 61
Could I omit the "2010" requirement and limit results to 61 rows? Is there a better way?
Much appreciate any help pointing me in the right direction!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做吗:
Can you just do this: