Oracle SQL: Query results from previous X isoweeks () (where X might be > 52)
- by tommy-o-dell
How could I adapt this query to show the previous 61 weeks? (still exlcluding the current week).
My query currently shows me the total weekly sales for 2010 grouped by ISO Week and ISO Year (exlcuding the current week).
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)
and to_char(order_date,'IYYY') = 2010
group by
to_char(order_date,'IYYY')
to_char(order_date,'IW')
I realize I could probably just omit the "2010" requirement, order by desc and limit results to a certain bnumber of rows. But that just doesn't seem right!
Much appreciate any help pointing me in the right direction!