Coding Test

Leetcode - 1407. Top Travellers

일시불

문제

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.

정답

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