Skip to content

1407. Top Travellers 👍

1
2
3
4
5
6
7
8
SELECT
  Users.name,
  IFNULL(SUM(Rides.distance), 0) AS travelled_distance
FROM Users
LEFT JOIN Rides
  ON (Users.id = Rides.user_id)
GROUP BY Users.id
ORDER BY 2 DESC, 1;