Table Schema
Inspect
Table
| Column | Type |
|---|---|
| trip_id | integer |
| pickup_location | varchar |
Find the most common pickup location.
Table Schema
| Column | Type |
|---|---|
| trip_id | integer |
| pickup_location | varchar |
Sample Data
| trip_id | pickup_location |
|---|---|
| 1 | A |
| 2 | B |
| 3 | A |
| 4 | C |
| 5 | A |
| 6 | B |
| 7 | A |
| pickup_location | trips |
|---|---|
| A | 4 |
SQL Editor
| pickup_location | trips |
|---|---|
| A | 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 pickup_location, COUNT(*) AS trips FROM trips GROUP BY pickup_location ORDER BY trips 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