Analyze sequential trends and partitioned cohorts without collapsing rows. Compute Month-over-Month (MoM) revenue acceleration, 3-day rolling moving averages, regional sales rankings, and user login gaps.
Key patterns and rules practiced in this track.
Accesses values from previous (LAG) or subsequent (LEAD) rows within the same partition without self-joining. Essential for MoM growth, velocity, and time deltas.
LAG(column, offset) OVER (PARTITION BY group_col ORDER BY sort_col)SELECT month, revenue, LAG(revenue) OVER (ORDER BY month) AS prev_rev, ROUND(100.0 * (revenue - LAG(revenue) OVER (ORDER BY month)) / LAG(revenue) OVER (ORDER BY month), 2) AS growth_pct FROM monthly_revenue;
Assigns sequential rank integers without skipping numbers in the event of ties. Ideal for "Top N items per category" queries.
DENSE_RANK() OVER (PARTITION BY partition_col ORDER BY rank_col DESC)SELECT rep_name, region, bookings, DENSE_RANK() OVER (PARTITION BY region ORDER BY bookings DESC) AS regional_rank FROM sales_reps;
Accumulates values over an ordered sliding window frame without collapsing the individual transaction records.
SUM(amount) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)SELECT entry_date, daily_net, SUM(daily_net) OVER (ORDER BY entry_date) AS running_balance FROM general_ledger;
Click any problem to open the interactive editor.
Time-series table showing month_date, revenue, prev_month_revenue, and growth_pct.
Filtered table with rep_name, region, total_bookings, and regional_rank containing only rank 1 and 2 reps per region.
Time-series showing entry_date, daily_net, and running_balance.
User login history with next session date and gap in days.
Daily sales alongside 3-day rolling window average.
Patient telemetry readings showing previous heart rate and BPM delta.
Transaction log showing the incremental card usage sequence number.
Drivers segmented into 4 earnings quartiles (1 = top 25%, 4 = bottom 25%).
Employee salary percentile within department on a 0.00 to 1.00 scale.
Monthly expansion MRR alongside cumulative cohort expansion total.
Order history showing order amount alongside the customer first purchase value.
ER patients categorized into 4 wait time quartiles.
Ledger lines showing running balance per account.
Trip log showing preceding dropoff timestamp per driver.
Run queries directly in your browser against realistic tables.