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.
- Prepare
- SQL
- Advanced Join
- Placements
- Discussions
Placements
Placements
Sort by
recency
|
1784 Discussions
|
Please Login in order to post a comment
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
My SQL:
select s.name from students s join friends f on s.id=f.id join packages p1 on s.id=p1.id join packages p2 on p2.id=f.friend_id where p2.salary > p1.salary order by p2.salary;
MY SQL