For each desk build a row for EVERY calendar date from the desk's first to its last trade_date (days without trades have daily_notional 0). rolling_7d_avg = average daily_notional over the current day and the 6 previous calendar days, counting zero days; near the desk's first date use only the days that exist (from the first date). Return desk, trade_date, daily_notional (ROUND 2) and rolling_7d_avg (ROUND 2). Order by desk, trade_date.
| Column | Type |
|---|---|
| trade_id | INTEGER |
| desk | TEXT |
| trade_date | DATE |
| notional | REAL |
| trade_id | desk | trade_date | notional |
|---|---|---|---|
| 1 | Rates | 2026-03-02 | 100 |
| 2 | Rates | 2026-03-03 | 150 |
| 3 | Rates | 2026-03-03 | 50 |
| 4 | Rates | 2026-03-05 | 300 |
| 5 | Rates | 2026-03-09 | 70 |
| 6 | FX | 2026-03-04 | 50 |
| 7 | FX | 2026-03-06 | 25 |
| desk | trade_date | daily_notional | rolling_7d_avg |
|---|---|---|---|
| FX | 2026-03-04 | 50 | 50 |
| FX | 2026-03-05 | 0 | 25 |
| FX | 2026-03-06 | 25 | 25 |
| Rates | 2026-03-02 | 100 | 100 |
| Rates | 2026-03-03 | 200 | 150 |
| Rates | 2026-03-04 | 0 | 100 |
| Rates | 2026-03-05 | 300 | 150 |
| Rates | 2026-03-06 | 0 | 120 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Normalise Messy Expense Claims · Structuring: Near-Threshold Deposits in 7 Days ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.