Rolling Revenue Windows

Start Timer

0:00:00

Upvote
8
Downvote
Save question
View comments

At Mozilla, browser usage and revenue are logged as individual transactions. We want to track revenue momentum by computing, for each day that has at least one transaction, the total revenue over that day plus the preceding days in two trailing windows.

Write a query that returns one row per transaction date with the total revenue for that day, the rolling 7-day revenue (the current day and the 6 days before it), and the rolling 30-day revenue (the current day and the 29 days before it).

transactions table

Column Type
id INTEGER
user_id INTEGER
created_at DATETIME
revenue FLOAT

Output:

Column Type
transaction_date DATE
daily_revenue FLOAT
rolling_7_day FLOAT
rolling_30_day FLOAT

Rules: - The rolling windows are based on calendar days, not row counts: a window may span fewer than 7 or 30 actual transaction days if some days have no transactions. - Sort the output by transaction_date ascending.

.
.
.
.
.


Comments

Loading comments