Completed rides by city
Grab's operations team wants to know how many completed rides happened in each city.
From the rides table, return the city and the number of completed rides (status = 'completed') as completed_rides, for every city that has at least one completed ride.
Schema
| id | INT |
| city | TEXT |
| status | TEXT |
| fare | NUMERIC(8,2) |
Example input
Stuck? Ask the coach for a nudge that won't give the answer away, or reveal the reference solution and a short walkthrough of why it works.
The interviewer's next question
Ops now cares about revenue, not ride count: return each city's total completed-ride fare as completed_revenue, but only for cities where that total exceeds RM 20. Order by city.
Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.
See Basic plansRM 25/mo · cancel anytime
Alongside the completed-ride count, show the average fare per completed ride for each city, rounded to 2 decimal places, as avg_fare.
Solving follow-ups — the questions an interviewer actually asks next — unlocks with a Basic plan.
See Basic plansRM 25/mo · cancel anytime