leetcode/1541_top-travellers/sql/solution.sql

7 lines
234 B
MySQL
Raw Normal View History

2022-04-27 19:06:11 +00:00
# Write your MySQL query statement below
SELECT Users.name as name, COALESCE(SUM(distance), 0) as travelled_distance
FROM Users
LEFT JOIN Rides ON Users.id = Rides.user_id
GROUP BY Users.id
ORDER BY travelled_distance DESC, name ASC;