Skip to content

2238. Number of Times a Driver Was a Passenger 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
WITH
  DriverIds AS (
    SELECT DISTINCT driver_id FROM Rides
  )
SELECT
  DriverIds.driver_id,
  COUNT(Rides.passenger_id) AS cnt
FROM DriverIds
LEFT JOIN Rides
  ON (DriverIds.driver_id = Rides.passenger_id)
GROUP BY 1;