Table Schema
Inspect
Table
| Column | Type |
|---|---|
| trip_id | integer |
| rider_id | integer |
| trip_date | date |
Find riders who completed more than 3 trips in a single day.
Table Schema
| Column | Type |
|---|---|
| trip_id | integer |
| rider_id | integer |
| trip_date | date |
Sample Data
| trip_id | rider_id | trip_date |
|---|---|---|
| 1 | 101 | 2024-01-01 |
| 2 | 101 | 2024-01-01 |
| 3 | 101 | 2024-01-01 |
| 4 | 101 | 2024-01-01 |
| 5 | 102 | 2024-01-01 |
| 6 | 102 | 2024-01-02 |
| rider_id |
|---|
| 101 |
SQL Editor
| rider_id |
|---|
| 101 |
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 DISTINCT rider_id FROM trips GROUP BY rider_id, trip_date HAVING COUNT(*) > 3;
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