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 FriendsSalary AS (
SELECT s.ID ,p.Salary FROM
Students s
JOIN Friends f ON f.ID=s.ID
JOIN Packages p ON p.ID=f.Friend_ID
), StudentsSalary AS
(
SELECT s.ID ,s.Name,p.Salary FROM
Students s
JOIN Friends f ON f.ID=s.ID
JOIN Packages p ON p.ID=s.ID
)
SELECT s.Name from StudentsSalary s
JOIN FriendsSalary f ON f.ID=s.ID
where f.Salary>s.Salary
ORDER BY f.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 FriendsSalary AS ( SELECT s.ID ,p.Salary FROM Students s JOIN Friends f ON f.ID=s.ID JOIN Packages p ON p.ID=f.Friend_ID ), StudentsSalary AS ( SELECT s.ID ,s.Name,p.Salary FROM Students s JOIN Friends f ON f.ID=s.ID JOIN Packages p ON p.ID=s.ID ) SELECT s.Name from StudentsSalary s JOIN FriendsSalary f ON f.ID=s.ID where f.Salary>s.Salary ORDER BY f.Salary