Sort by

recency

|

1715 Discussions

|

  • + 0 comments

    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;

  • + 0 comments

    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

  • + 0 comments

    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

        MS SQL
    
  • + 0 comments

    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

  • + 0 comments
    WITH student_friend_salary AS(
        SELECT f.ID as student_id,s.Name, p.Salary as s_salary, f.Friend_ID, ps.Salary as Best_friend_salary
        FROM Students s
        JOIN Friends f ON s.ID = f.ID
        JOIN packages p ON p.ID = f.ID
        JOIN Packages ps ON ps.ID = f.Friend_ID
    )
    SELECT Name
    FROM student_friend_salary
    WHERE s_salary < Best_friend_salary
    ORDER BY Best_friend_salary