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 OwnSalaryTable AS (
SELECT f.ID, f.Friend_ID, p.Salary AS "My_salary"
FROM Friends f
JOIN Packages p ON f.ID = p.ID
), TotalSalaryTable AS (
SELECT ost.ID, ost.Friend_ID, ost.My_salary, p.Salary AS "Friend_salary"
FROM OwnSalaryTable ost
JOIN Packages p ON ost.Friend_ID = p.ID
)
SELECT s.Name
FROM Students s
JOIN TotalSalaryTable tst ON s.ID = tst.ID
WHERE tst.My_salary < tst.Friend_salary
ORDER BY tst.Friend_salary
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 OwnSalaryTable AS ( SELECT f.ID, f.Friend_ID, p.Salary AS "My_salary" FROM Friends f JOIN Packages p ON f.ID = p.ID ), TotalSalaryTable AS ( SELECT ost.ID, ost.Friend_ID, ost.My_salary, p.Salary AS "Friend_salary" FROM OwnSalaryTable ost JOIN Packages p ON ost.Friend_ID = p.ID ) SELECT s.Name FROM Students s JOIN TotalSalaryTable tst ON s.ID = tst.ID WHERE tst.My_salary < tst.Friend_salary ORDER BY tst.Friend_salary