Consider only trips with status 'completed'. Order each rider's completed trips by `requested_at` (ties by `trip_id`). A rider *repeats* if their 2nd completed trip was requested at most 7 days (7 * 24 hours, inclusive) after the 1st. Per `signup_city` (only cities with at least one rider who completed a trip) return `signup_city`, `riders_with_trip`, `repeat_7d`, `repeat_pct` (ROUND 1). Order by `repeat_pct` DESC, then `signup_city`.
| Column | Type |
|---|---|
| rider_id | INTEGER |
| signup_city | TEXT |
| rider_id | signup_city |
|---|---|
| 1 | Delhi |
| 2 | Delhi |
| 3 | Delhi |
| 4 | Mumbai |
| 5 | Mumbai |
| 6 | Goa |
| Column | Type |
|---|---|
| trip_id | INTEGER |
| rider_id | INTEGER |
| requested_at | TIMESTAMP |
| status | TEXT |
| trip_id | rider_id | requested_at | status |
|---|---|---|---|
| 1 | 1 | 2026-09-01 08:00:00 | completed |
| 2 | 1 | 2026-09-03 09:00:00 | completed |
| 3 | 2 | 2026-09-01 10:00:00 | completed |
| 4 | 2 | 2026-09-05 10:00:00 | cancelled |
| 5 | 2 | 2026-09-20 10:00:00 | completed |
| 6 | 3 | 2026-09-02 10:00:00 | completed |
| 7 | 4 | 2026-09-02 11:00:00 | completed |
| 8 | 4 | 2026-09-09 11:00:00 | completed |
| signup_city | riders_with_trip | repeat_7d | repeat_pct |
|---|---|---|---|
| Mumbai | 2 | 1 | 50 |
| Delhi | 3 | 1 | 33.3 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Sensor Online Periods · De-duplicate Multi-Device Playback Logs ›
{{ 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.