Snoopy [해커랭크/MySQL] 44. Placements
코딩테스트/해커랭크 SQL

[해커랭크/MySQL] 44. Placements

Sooyoon Jeong 2023. 4. 13.
 

🤔 문제 분석

1. There are 3 query. 

2. Write a query to output the names of those students whose best friends got offered a higher salary than them.

3. 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 S.Name
FROM Students AS S
    INNER JOIN (SELECT F.ID, F.Friend_ID, P.Salary
                FROM Friends AS F
                INNER JOIN Packages AS P ON F.Friend_ID = P.ID) AS sub ON S.ID = sub.ID
    INNER JOIN Packages AS P ON S.ID = P.ID
WHERE P.Salary < sub.Salary
ORDER BY sub.Salary

 

댓글