Placements | HackerRank
Write a query to output the names of those students whose best friends got offered a higher salary than them.
www.hackerrank.com
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 Input
Now,
- Samantha's best friend got offered a higher salary than her at 11.55
- Julia's best friend got offered a higher salary than her at 12.12
- Scarlet's best friend got offered a higher salary than her at 15.2
- Ashley's best friend did NOT get offered a higher salary than her
The name output, when ordered by the salary offered to their friends, will be:
- Samantha
- Julia
- Scarlet
[My Answer]
SELECT A.name
FROM students A
inner join
friends B on A.id = B.id
inner join
packages C on A.id = C.id
inner join
packages D on B.friend_id = D.id
WHERE C.salary < D.salary
ORDER BY D.salary
이제 조인 차례인가보다
'Code Problems > SQL_ HackerRank' 카테고리의 다른 글
[HackerRank] African Cities (0) | 2022.01.03 |
---|---|
[HackerRank] Population Census (0) | 2021.12.31 |
[HackerRank] Weather Observation Station 20 (0) | 2021.12.28 |
[HackerRank] Weather Observation Station 19 (0) | 2021.11.26 |
[HackerRank] Weather Observation Station 18 (0) | 2021.11.26 |