members has one row per patient (patient_id, region) and service_contacts has one row per support call (call_id, patient_id). Count each member's calls (0 if none; calls from patients not in members are ignored) and return, for each region, the member or members with the highest call count. Output columns: region, patient_id, call_count. Order by region, then patient_id.
| Column | Type |
|---|---|
| patient_id | INTEGER |
| region | TEXT |
| patient_id | region |
|---|---|
| 101 | East |
| 102 | East |
| 103 | West |
| 104 | West |
| Column | Type |
|---|---|
| call_id | INTEGER |
| patient_id | INTEGER |
| call_id | patient_id |
|---|---|
| 1 | 101 |
| 2 | 101 |
| 3 | 102 |
| 4 | 103 |
| 5 | 103 |
| 6 | 103 |
| 7 | 104 |
| region | patient_id | call_count |
|---|---|---|
| East | 101 | 2 |
| West | 103 | 3 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Monthly Support Volume Change · Near-Duplicate Transfers ›
{{ 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.