← Questions

Carpool ride metrics in SQL

0
MetaCodingLast asked Aug 2025

A coding interview question asked in Meta's AI-enabled coding round, last asked Aug 2025. It tests sql, aggregation and data engineering.

A ride-sharing product lets riders share a car (pooled rides). Using the tables below, write SQL for a set of daily metrics. Define each metric precisely before you write its query.

Interface

Unless you agree on a different interface with the interviewer, assume these tables:

  • users(user_id, name, signup_date)
  • drivers(driver_id, user_id)
  • pooled_rides(pool_id, driver_id, start_time, end_time, status, seat_capacity) — one row per shared vehicle journey.
  • pool_bookings(booking_id, pool_id, rider_id, seats_booked, status, created_at, cancel_time) — booking status is one of completed, no_show, cancelled_by_rider, cancelled_by_driver.

Return one row per calendar date that appears in a completed ride's end_time or in a booking's created_at, with:

  1. completed_pooled_rides — completed pooled rides that ended that day.
  2. avg_seats_utilized — for those rides, the average of seats from completed bookings per ride. No-shows and cancellations do not count.
  3. cancellation_rate — bookings created that day with a cancelled status, divided by all bookings created that day.

Example

pooled_rides:  10  completed  ended 2025-03-01 08:40
               11  completed  ended 2025-03-01 18:30
               12  cancelled
pool_bookings: 100 pool 10  2 seats  completed            created 2025-03-01
               101 pool 10  1 seat   completed            created 2025-03-01
               102 pool 10  1 seat   no_show              created 2025-03-01
               103 pool 11  1 seat   completed            created 2025-03-01
               104 pool 11  2 seats  cancelled_by_rider   created 2025-03-01
               105 pool 12  1 seat   cancelled_by_driver  created 2025-03-02

date        completed_pooled_rides  avg_seats_utilized  cancellation_rate
2025-03-01  2                       2.00                0.20      # (3 + 1) / 2; 1 of 5 cancelled
2025-03-02  0                       NULL                1.00

Clarifying questions

  • Is a ride's day its start time or its end time? Which time zone?
  • Does a completed ride with no completed bookings count, with 0 seats?
  • Do no-shows count as cancellations in the rate?
  • Should days with no activity appear with zeros?

What a strong answer covers

  • Seats per ride aggregated first in a subquery, then averaged per day. Averaging over bookings directly would weight rides by their number of bookings.
  • Conditional aggregation (SUM(CASE WHEN ... END)) for the cancellation rate, and decimal division with NULLIF against division by zero.
  • Combining the two daily results with a FULL OUTER JOIN or a union of dates, so days with only bookings or only rides still appear.
  • Clear metric definitions stated before the SQL, and the edge cases decided.
  • Optionally without CTEs, using subqueries in FROM.

Follow-ups

  • Average seat utilization as a share of seat_capacity.
  • Share of rides that actually pooled two or more riders.
  • Week-over-week change of each metric.

Where it's asked

  • Meta · AI-enabled coding · Last asked Aug 202560 min · Several progressive tasks on a starter codebase in CoderPad with an AI assistant panel; usually two rounds · The first task usually without AI, later tasks with it

What it tests

sql · aggregation · data engineering

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding