Oracle SQL: Query results from previous X isoweeks () (where X might be > 52)
Posted
by tommy-o-dell
on Stack Overflow
See other posts from Stack Overflow
or by tommy-o-dell
Published on 2010-03-24T06:44:08Z
Indexed on
2010/03/24
7:43 UTC
Read the original article
Hit count: 212
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!
© Stack Overflow or respective owner