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
|
1715 Discussions
|
Please Login in order to post a comment
WITH Friend_Salary AS ( SELECT Students.ID, Students.Name, Friends.Friend_ID, Student_Package.Salary AS Student_Salary, Friend_Package.Salary AS Friend_Salary FROM Students INNER JOIN Friends ON Students.ID = Friends.ID INNER JOIN Packages AS Student_Package ON Students.ID = Student_Package.ID INNER JOIN Packages AS Friend_Package ON Friends.Friend_ID = Friend_Package.ID ) SELECT Name FROM Friend_Salary WHERE Friend_Salary.Friend_Salary > Friend_Salary.Student_Salary ORDER BY Friend_Salary.Friend_Salary ASC;
MS SQL Server
with salary_cte as ( select s.id as id, s.name as name, p1.salary as salary, f1.friend_id as friend_id, p2.salary as friend_salary from Students s join Friends f1 on s.id = f1.id join Packages p1 on s.id = p1.id join Packages p2 on f1.friend_id = p2.id)
select name from salary_cte where friend_salary > salary order by friend_salary
select g.name from ( select e.,f.salary from ( select a.,b.friend_id,b.salary as friend_salary from ( select * from students )a
left join ( select c.*,d.salary from ( select * from friends )c left join ( select * from packages )d on c.friend_id=d.id )b on a.ID=b.ID )e left join ( select * FROM packages )f on e.ID=f.ID )g where friend_salary>salary order by friend_salary MSSQL
with TheirSalary as( select Name,P.Salary,F.Friend_Id from Students as S inner join Packages as P on S.Id = P.Id inner join Friends as F on S.Id = F.Id ) select Name from TheirSalary as TS inner join Packages as P on TS.Friend_Id = P.Id and P.Salary > TS.Salary order by P.salary