[HackerRank] Placements

mzzzi·2022년 4월 25일
0

HackerRank SQL

목록 보기
51/52
post-thumbnail

MySQL > 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 them. Names must be ordered by the salary amount offered to the best friends. It is guaranteed that no two students got same salary offer.


Sample Output

Samantha
Julia
Scarlet

My Answer


SELECT S.NAME
FROM STUDENTS S JOIN PACKAGES P ON S.ID = P.ID
                JOIN FRIENDS F ON S.ID = F.ID 
                JOIN PACKAGES P1 ON F.FRIEND_ID = P1.ID
WHERE P.SALARY < P1.SALARY
ORDER BY P1.SALARY
profile
무럭무럭 성장하라🌳

0개의 댓글