For Q1 2026 (close_date from 2026-01-01 to 2026-03-31 inclusive) compute each rep's won_amount = sum of 'Closed Won' deals (0 if none) and attainment_pct = 100 * won_amount / quarterly_quota, ROUND to 1. Every rep must appear, even with no deals. Rank reps within their region by attainment_pct using DENSE_RANK (highest = 1). Return region, rep_name, won_amount (ROUND 2), attainment_pct, region_rank. Order by region, region_rank, rep_name.
| Column | Type |
|---|---|
| rep_id | INTEGER |
| rep_name | TEXT |
| region | TEXT |
| quarterly_quota | REAL |
| rep_id | rep_name | region | quarterly_quota |
|---|---|---|---|
| 1 | Anita | North | 100000 |
| 2 | Bilal | North | 80000 |
| 3 | Carlos | South | 120000 |
| 4 | Divya | South | 100000 |
| 5 | Elena | South | 90000 |
| Column | Type |
|---|---|
| deal_id | INTEGER |
| rep_id | INTEGER |
| close_date | DATE |
| amount | REAL |
| stage | TEXT |
| deal_id | rep_id | close_date | amount | stage |
|---|---|---|---|---|
| 1 | 1 | 2026-01-15 | 50000 | Closed Won |
| 2 | 1 | 2026-02-20 | 40000 | Closed Won |
| 3 | 2 | 2026-03-05 | 80000 | Closed Won |
| 4 | 2 | 2026-03-20 | 10000 | Closed Lost |
| 5 | 3 | 2026-02-11 | 60000 | Closed Won |
| 6 | 4 | 2026-01-09 | 30000 | Closed Won |
| 7 | 4 | 2026-04-02 | 90000 | Closed Won |
| 8 | 5 | 2026-03-31 | 45000 | Closed Won |
| region | rep_name | won_amount | attainment_pct | region_rank |
|---|---|---|---|---|
| North | Bilal | 80000 | 100 | 1 |
| North | Anita | 90000 | 90 | 2 |
| South | Carlos | 60000 | 50 | 1 |
| South | Elena | 45000 | 50 | 1 |
| South | Divya | 30000 | 30 | 2 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Average Time Spent In Progress · Peak Request Hour per City ›
{{ 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.