Paths Subjects Questions Quizzes Pricing Search
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
  1. What does the query return for cum_signups on each row, and why?
  2. Fix it so the count increases by exactly one per row.
  3. 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

← Back to SQL for Data Analysis practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.