HackerRank SQL 문제 풀기 - Placements
2025. 1. 5. 11:33ㆍ프로그래밍/SQL
반응형
안녕하세요? 분석하는 디제이입니다.
오늘은 HackerRank 사이트에 있는 SQL문제를 풀어보려고 합니다.
난이도는 Intermediate구요, 제목은 Placements입니다.
문제입니다.
You are given three tables: Students, Friends and Packages. Students contains two columns: ID and Name.
Friends contains two columns: ID and Friend_ID(ID of the ONLY best friend).
Packages contains two columns: ID and Salary(offered salary in thousands per month).

Write a query to output the names of those students whose best friends got offered a higher salary than then.
Names must be ordered by the salary amount offered to the best friends. It is guaranteed that no two students got same salary offer.

정답입니다.
제가 작성한 정답입니다.
SELECT
A.NAME
FROM STUDENTS AS A
INNER JOIN FRIENDS AS B ON A.ID = B.ID
LEFT JOIN PACKAGES AS C ON A.ID = C.ID
LEFT JOIN PACKAGES AS D ON B.FRIEND_ID = D.ID
WHERE C.SALARY < D.SALARY
ORDER BY D.SALARY
궁금한 점 있으시면 댓글 달아주세요.
감사합니다.
반응형