IntermediateCTEs & Recursion25 points

Rider cohorts by month of first trip

The growth team groups riders into cohorts by the month of their first ride request (the earliest requested_at of any status). Riders who never requested a ride belong to no cohort. They want to see whether early cohorts become heavier users than recent ones, so the cohorts need volume and a heavy-user count. A rider is heavy when they made 10 or more requests in total in the data.

Task: use CTEs to return one row per cohort with cohort_month (YYYY-MM), riders (riders in that cohort), total_trips (all requests of those riders, any status), trips_per_rider (ROUND(x, 2)) and heavy_riders. Sort by cohort_month ascending.

The data you can query

Each table is shown with its column types and the first rows, so you can see exactly what the data looks like.

cities4 rows
id INTEGERname TEXTcountry TEXT
1DubaiUAE
2LahorePakistan
3SingaporeSingapore
4NairobiKenya
drivers8 rows
id INTEGERname TEXTcity_id INTEGERjoined_on TEXTvehicle_type TEXT
1Rashid Al Mansoori12025-09-18Economy
2Tariq Mehmood22026-02-05Economy
3Wei Jie Tan32025-09-08Comfort
4Samuel Kiptoo42025-11-12Economy
5Hassan Qureshi12025-12-20Economy
6Priya Raman22025-06-24Economy

Showing the first 6 of 8 rows.

riders32 rows
id INTEGERname TEXThome_city_id INTEGERsignup_date TEXT
1Ayesha Khan12026-03-09
2Bilal Okafor22026-02-26
3Chen Silva32026-03-12
4Diego Tanaka42026-03-30
5Elena Weber12026-06-04
6Farid Nguyen22026-05-23

Showing the first 6 of 32 rows.

trips548 rows
id INTEGERrider_id INTEGERdriver_id INTEGERcity_id INTEGERrequested_at TEXTstatus TEXTdistance_km REALfare_usd REALsurge REALrating INTEGER
11512026-04-06 08:23:01Completed46.915
24842026-04-06 10:42:25Completed13.19.441.255
33332026-04-06 13:24:49Completed3.55.5315
42222026-04-06 17:17:07Completed15.89.51.54
51112026-04-06 18:25:11Completed11.819.351.254
64842026-04-06 21:01:43Completed16.69.314

Showing the first 6 of 548 rows.

Your query runs on SQLite. Write a single SELECT; use LIMIT instead of TOP.