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!