如何调整此查询以显示之前(例如 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 行吗?有更好的办法吗?
非常感谢任何为我指明正确方向的帮助!
最佳答案
你能这样做吗:
select
to_char(order_date,'IYYY') as iso_year,
to_char(order_date,'IW') as iso_week,
sum(sale_amount)
from orders
where order_date >= TRUNC(SYSDATE,'IW') - (61 * 7)
and order_date < TRUNC(SYSDATE,'IW')
group by
to_char(order_date,'IYYY'),
to_char(order_date,'IW')
关于sql - Oracle SQL : Query results from previous X isoweeks () (where X might be > 52),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2505822/