Published on

Leetcode - 1407. Top Travellers

Authors
  • avatar
    Name
    Indo Yoon
    Twitter
Table of Contents

문제

[Loading...

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

LeetCode

](https://leetcode.com/problems/top-travellers/)

정답

SELECT Users.name,
IF (ISNULL(sum(Rides.distance)), 0, sum(Rides.distance)) as travelled_distance
FROM Users
LEFT JOIN Rides ON Users.id = Rides.user_id
GROUP BY Users.id
ORDER BY travelled_distance DESC, name