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
|
1876 Discussions
|
Please Login in order to post a comment
select student_name from (select s.id student_id, s.name student_name, p.salary student_salary,
f.friend_id friend_id, f.friend_name friend_name, f.friend_salary friend_salary from students s join packages p on p.id = s.id join (select ff.id, ff.friend_id, i.name as friend_name, pp.salary as friend_salary from friends ff join packages pp on pp.id = ff.friend_id join students i on i.id = ff.friend_id ) as f on f.id = s.id ) as mains where student_salary < friend_salary order by friend_salary
****select s.name from Students s join Friends f on s.id = f.id join Packages p on s.id = p.id join Packages fp on f.friend_id = fp.id where fp.salary > p.salary order by fp.salary;
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 f.Friend_ID = p2.ID WHERE p2.Salary > p1.Salary ORDER BY p2.Salary;
SQL Server -
WITH cte1 as ( SELECT S.ID as ID,S.Name as Name,P.Salary as Salary FROM Students S JOIN Packages P ON S.ID = P.ID ), cte2 as ( SELECT F.ID,F.Friend_ID as FriendsID, P.Salary as FriendsSalary FROM Packages P JOIN Friends F ON F.Friend_ID = P.ID
) SELECT c1.Name FROM cte1 c1 JOIN cte2 c2 ON c1.ID = c2.ID WHERE c2.FriendsSalary > c1.Salary ORDER BY c2.FriendsSalary