Search

Placements

์„ธ ๊ฐœ์˜ ํ…Œ์ด๋ธ”์ด ์ œ๊ณต
Studentsย 
โ€ข
ID
โ€ข
Name
Friends
โ€ข
ID
โ€ข
Friend_ID ย (ID ย of the ONLY best friend).
Packages
โ€ข
ID
โ€ข
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 Output
Samantha Julia Scarlet
Plain Text
๋ณต์‚ฌ
โ€ข
ํ‹€๋ฆผ
SELECT MyName FROM ( SELECT S.Name MyName, P1.Salary Salary1, P2.Salary Salary2 FROM Friends F JOIN Students S ON S.ID = F.ID JOIN Packages P1 ON P1.ID = S.ID JOIN Packages P2 ON P2.ID = F.Friend_ID ) T WHERE Salary1 < Salary2 ORDER BY Salary2 DESC -- ์ด๋ถ€๋ถ„์ด ํ‹€๋ฆผ ;
SQL
๋ณต์‚ฌ
โ€ข
ASC order - ์ •๋‹ต
SELECT MyName FROM ( SELECT S.Name MyName, P1.Salary Salary1, P2.Salary Salary2 FROM Friends F JOIN Students S ON S.ID = F.ID JOIN Packages P1 ON P1.ID = S.ID JOIN Packages P2 ON P2.ID = F.Friend_ID ) T WHERE Salary1 < Salary2 ORDER BY Salary2 ;
SQL
๋ณต์‚ฌ