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.
아래의 조건으로 Name 조회하기
- 자신의 급여(salary)보다 친구의 급여(salary)가 높은 사람의 이름 조회하기
- 이를 친구의 급여(salary) 오름차순
SELECT
S.Name
FROM
Students AS S
INNER JOIN Friends AS F
ON S.ID = F.ID
INNER JOIN Packages AS P
ON F.ID = P.ID
INNER JOIN Packages AS P2
ON F.Friend_ID = P2.ID
WHERE P.salary < P2.salary
ORDER BY P2.salary;
'MYSQL 코테 준비' 카테고리의 다른 글
[HacKerRank SQL] SQL Project Planning - MYSQL (0) | 2021.03.09 |
---|---|
[HacKerRank SQL] Ollivander's Inventory - MYSQL (0) | 2021.02.25 |
[HacKerRank SQL] Top Competitors - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] The Report - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] Asian Population- MYSQL (0) | 2021.02.24 |
댓글