728x90
※ 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).
■ [Advanced Join] Placements
https://www.hackerrank.com/challenges/placements/problem?isFullScreen=true
Q.
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.
A.
SELECT
S.NAME
FROM
STUDENTS S
,(
SELECT
F.ID AS MY_ID
,P1.SALARY AS MY_SAL
,F.FRIEND_ID AS FND_ID
,P2.SALARY AS FND_SAL
FROM
FRIENDS F
, PACKAGES P1
, PACKAGES P2
WHERE 1=1
AND F.ID = P1.ID
AND F.FRIEND_ID = P2.ID
AND P1.SALARY < P2.SALARY
) F_P_FL
WHERE 1=1
AND S.ID = F_P_FL.MY_ID
ORDER BY
F_P_FL.FND_SAL;
반응형
'코딩 문제 풀기 ( Algorithm problem solving ) > 해커랭크 ( HackerRank )' 카테고리의 다른 글
[HackerRank][SQL(Oracle)] Contest Leaderboard (0) | 2023.03.29 |
---|---|
[HackerRank][SQL(Oracle)] Binary Tree Nodes (0) | 2023.03.29 |
[HackerRank][SQL(Oracle)] Draw The Triangle 1, 2 (0) | 2023.03.29 |
[HackerRank][SQL(Oracle)] Type of Triangle (0) | 2023.03.29 |
[HackerRank][SQL(Oracle)] Average Population of Each Continent, Population Census, African Cities (0) | 2023.03.27 |