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
overall AS (
SELECT s.ID, s.Name, p.Salary
FROM Students s
LEFT JOIN Packages p ON s.ID = p.ID
)
SELECT a.name
FROM (
SELECT f.ID, s.Name as name, s.Salary as s_salary,
f.Friend_ID, b.Salary as b_salary
FROM Friends f
LEFT JOIN overall s ON f.ID = s.ID
LEFT JOIN overall b ON f.Friend_ID = b.ID
) a
WHERE a.b_salary > a.s_salary
ORDER BY a.b_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 overall AS ( SELECT s.ID, s.Name, p.Salary FROM Students s LEFT JOIN Packages p ON s.ID = p.ID )
SELECT a.name FROM ( SELECT f.ID, s.Name as name, s.Salary as s_salary, f.Friend_ID, b.Salary as b_salary FROM Friends f LEFT JOIN overall s ON f.ID = s.ID LEFT JOIN overall b ON f.Friend_ID = b.ID ) a WHERE a.b_salary > a.s_salary ORDER BY a.b_salary;
`