Table Schema
Inspect
Table
| Column | Type |
|---|---|
| booking_id | integer |
| city | varchar |
Find the city with the highest number of bookings.
Table Schema
| Column | Type |
|---|---|
| booking_id | integer |
| city | varchar |
Sample Data
| booking_id | city |
|---|---|
| 1 | NYC |
| 2 | SF |
| 3 | NYC |
| 4 | LA |
| 5 | NYC |
| 6 | SF |
| 7 | NYC |
| city | total_bookings |
|---|---|
| NYC | 4 |
SQL Editor
| city | total_bookings |
|---|---|
| NYC | 4 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT city, COUNT(*) AS total_bookings FROM bookings GROUP BY city ORDER BY total_bookings DESC LIMIT 1;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions