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
|
1759 Discussions
|
Please Login in order to post a comment
select s.name from students s join friends f on s.id = f.id join ( select salary, id from packages where id in (select friend_id from friends) ) f_sal on f_sal.id = f.Friend_ID join packages p on s.id = p.id where f_sal.salary > p.salary order by f_sal.salary ;
with CTE as (select s.id, s.name, p.salary as salary, f.friend_ID, p2.salary as salary_2 from Students s join friends f on f.id=s.id join Packages p on p.ID= s.id join packages p2 on f.Friend_ID = p2.id) select name from CTE where salary_2>salary order by salary_2;
My SQL solution select name from students s join friends f on s.id=f.id join packages p on f.id=p.id join packages p1 on f.friend_id=p1.id where p.salary
select s.name from friends f join packages p1 on f.friend_ID=p1.ID join packages p2 on f.ID=p2.ID join students s on s.id=f.id where p1.salary>p2.salary order by p1.salary