Rolling Windows Flashcards

(2 cards)

1
Q

what does PARTITION BY do in window functions?

A

You are telling SQL:

if you do partition by date:

–> Reset the window every date.
–> never do this with 7-day /30 -day windows, etc.

if you do partition by user_id
–> Reset the window every user_id.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

7 day rolling widnow

A

SELECT
event_date,
COUNT(DISTINCT user_id) OVER (
ORDER BY event_date
RANGE BETWEEN INTERVAL 6 DAY PRECEDING AND CURRENT ROW
) AS rolling_7d_active_users
FROM events;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly