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.
select S.id, S.friend_id, SP.salary AS Salary, FP.Salary AS friendsalary
FROM Friends S
left join Packages SP
ON S.id=SP.id
left join Packages FP
ON S.friend_id=FP.id
)
SELECT S.Name FROM Students S
join SalryCTE SC ON S.id=SC.id
where SC.friendsalary>SC.Salary
order by SC.friendsalary;
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 SalryCTE AS (
select S.id, S.friend_id, SP.salary AS Salary, FP.Salary AS friendsalary FROM Friends S left join Packages SP ON S.id=SP.id left join Packages FP ON S.friend_id=FP.id ) SELECT S.Name FROM Students S join SalryCTE SC ON S.id=SC.id where SC.friendsalary>SC.Salary order by SC.friendsalary;