rolling 13 weeks of data.

Database

rolling 13 weeks of data.

Spoiler
 

Hi, Can you please help me to create a rolling 13 weeks query.

1 REPLY
New Member

Re: rolling 13 weeks of data.

rolling forward, or backward?

one row per week or per day?

 

This will give you a starting point.

This shows a rolling 13 weeks in the past, not counting current week. 

The SYS_CALENDAR.CALENDAR has the first day of the week as Sunday.

 

SELECT C.CALENDAR_DATE
, C.WEEK_OF_CALENDAR - W.WEEK_OF_CALENDAR AS WEEKS_AGO
FROM SYS_CALENDAR.CALENDAR C
, (SELECT WEEK_OF_CALENDAR
FROM SYS_CALENDAR.CALENDAR
WHERE CALENDAR_DATE = DATE) W
WHERE C.WEEK_OF_CALENDAR - W.WEEK_OF_CALENDAR BETWEEN -13 AND -1
ORDER BY 1