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
|
1778 Discussions
|
Please Login in order to post a comment
SELECT s.name FROM students s JOIN packages sp ON s.id = sp.id JOIN friends f ON s.id = f.id JOIN packages fp ON f.friend_id = fp.id WHERE fp.salary > sp.salary ORDER BY fp.salary;
;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;
with cte1 as( SELECT s.id as id, s.name as name, p.salary as salary, f.friend_id as friend_id FROM Students s JOIN Friends f ON s.id = f.id JOIN packages p ON s.id = p.id) SELECT c1.name as main_name FROM cte1 c1 JOIN students s1 ON c1.friend_id = s1.id JOIN packages p2 ON p2.id = s1.id WHERE p2.salary > c1.salary ORDER BY p2.salary;