일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- sql
- tableau
- Queue
- 코딩테스트
- coding
- 프로그래머스
- 조합
- mysql
- cte
- Growth hacking
- programmers
- 완전탐색
- coding test
- python
- AARRR
- time complexity
- collections
- level4
- import re
- Level2
- 코딩
- lambda
- lv4
- itertools
- counter
- join
- 코테
- hackerrank
- Stack
- 파이썬
Archives
- Today
- Total
ror_coding
[HackerRank] Placements 본문
728x90
Question
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
Sample Output
Samantha
Julia
Scarlet
Explanation
See the following table:
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
Code
SELECT S.NAME
FROM STUDENTS S
JOIN FRIENDS F ON S.ID = F.ID
JOIN PACKAGES PS ON S.ID = PS.ID
JOIN PACKAGES PF ON F.FRIEND_ID = PF.ID
WHERE PS.SALARY < PF.SALARY
ORDER BY PF.SALARY
now me

728x90
'Coding Test > SQL' 카테고리의 다른 글
[HackerRank] Top Earners (0) | 2025.06.14 |
---|---|
[HackerRank] The Report (0) | 2025.06.14 |
[HackerRank] Type of Triangle (0) | 2025.06.14 |
[HackerRank] Symmetric Pairs (0) | 2025.06.14 |
[HackerRank] Binary Tree Nodes (0) | 2025.04.05 |