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 CTE AS(
select s.id,s.name,f.friend_id,p.salary as salary, q.salary as friendssalary
from students s
INNER JOIN Friends f ON s.id=f.id
INNER JOIN packages p ON s.id=p.id
INNER JOIN packages q ON f.friend_id=q.id
)
select name from CTE
where friendssalary>salary
order by friendssalary
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 →
MS SQL Server
WITH CTE AS( select s.id,s.name,f.friend_id,p.salary as salary, q.salary as friendssalary from students s INNER JOIN Friends f ON s.id=f.id INNER JOIN packages p ON s.id=p.id INNER JOIN packages q ON f.friend_id=q.id
) select name from CTE where friendssalary>salary order by friendssalary