Intermediate
Open
Pro
The Running Total That Jumps in Steps
You compute a cumulative count of sign-ups ordered by signup date:
SELECT user_id, signup_date,
COUNT(*) OVER (ORDER BY signup_date) AS cum_signups
FROM users
ORDER BY signup_date, user_id;
With this data:
user_id signup_date
1 2026-01-01
2 2026-01-02
3 2026-01-02
4 2026-01-03
- What does the query return for
cum_signupson each row, and why? - Fix it so the count increases by exactly one per row.
- Now write a query that returns, per user, the amount of their previous paid order and the 3-order moving average of paid amounts, and explain what happens at the first order of each user.
Share this question