We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
WITH t as(
SELECT S.ID AS ID, S.Name AS Name, P.Salary AS Salary,
(SELECT Salary FROM Packages WHERE ID = F.Friend_ID) AS Friend_Salary
FROM Students S JOIN Friends F
ON S.ID = F.ID
JOIN Packages P ON F.ID = P.ID
)
SELECT Name From t
WHERE Friend_Salary > Salary
ORDER BY Friend_Salary ASC
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Placements
You are viewing a single comment's thread. Return to all comments →
WITH t as( SELECT S.ID AS ID, S.Name AS Name, P.Salary AS Salary, (SELECT Salary FROM Packages WHERE ID = F.Friend_ID) AS Friend_Salary FROM Students S JOIN Friends F ON S.ID = F.ID JOIN Packages P ON F.ID = P.ID
) SELECT Name From t WHERE Friend_Salary > Salary ORDER BY Friend_Salary ASC