LeetCode - 1407. Top Travellers (MySQL)

조민수·2024년 6월 10일
0

LeetCode

목록 보기
29/61

Easy, SQL - LEFT JOIN, IFNULL

RunTime : 1224 ms


문제

Write a solution to report the distance traveled by each user.

Return the result table ordered by travelled_distance in descending order, if two or more users traveled the same distance, order them by their name in ascending order.

The result format is in the following example.


풀이

  • 프로그래머스 Lv3 정도 되는 문제
    • Easy 보단 Medium에 가깝지 않나
SELECT U.name, IFNULL(SUM(R.distance), 0) as travelled_distance 
FROM Users as U LEFT JOIN Rides as R ON U.id = R.user_id
GROUP BY R.user_id
ORDER BY 2 desc, 1 asc;
profile
사람을 좋아하는 Front-End 개발자

0개의 댓글