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 f.id,f.friend_id,s.name,p.Salary
from friends as f
Left join students as s
on f.id=s.id
Left join Packages as p
on f.id=p.id
),
cte2 as(
select distinct c1.salary,c2.name from cte as c1
join cte as c2
on c1.id=c2.friend_id
where c1.salary>c2.salary
)
select name from cte2 order by salary asc
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 cte as(
select f.id,f.friend_id,s.name,p.Salary from friends as f Left join students as s on f.id=s.id Left join Packages as p on f.id=p.id ), cte2 as( select distinct c1.salary,c2.name from cte as c1 join cte as c2 on c1.id=c2.friend_id where c1.salary>c2.salary
)
select name from cte2 order by salary asc