Sort by

recency

|

1923 Discussions

|

  • + 0 comments

    MySQL - simplest solution using join

    select s1.name
    from Students s1
    join Friends f1
    on s1.ID = f1.ID
    join Packages p1
    on f1.Friend_ID = p1.ID
    join Packages p2
    on f1.ID = p2.ID
    where p1.salary > p2.salary
    order by p1.salary
    
  • + 0 comments
    select s.name
    from Students s
    left join Friends f on s.id = f.id
    left join packages own_sal on s.id = own_sal.id
    left join packages frnd_sal on f.friend_id = frnd_sal.id
    where own_sal.salary<frnd_sal.salary
    order by frnd_sal.salary
    
  • + 0 comments

    WITH CTESAL AS (SELECT S.NAME AS NAME,P.SALARY AS MySAL,F.FRIEND_ID,PA.SALARY AS FRSAL FROM STUDENTS S JOIN PACKAGES P ON S.ID = P.ID JOIN FRIENDS F ON F.ID= S.ID JOIN PACKAGES PA ON F.FRIEND_ID = PA.ID WHERE P.SALARY < PA.SALARY ORDER BY PA.SALARY ASC) SELECT NAME FROM CTESAL

  • + 0 comments

    with cte_stu as( select F.ID,s.name,P.Salary from Friends F join Packages P on F.ID=P.ID join Students s on F.ID=s.ID),

    cte_fri as(
    select F.Friend_ID,s.name,P.Salary
    from Friends F join Packages P on Friend_ID=P.ID
    join Students s on  Friend_ID=s.ID)
    

    Select st.name from
    cte_stu St join Friends F on ST.ID=F.ID join cte_fri fr on fr.Friend_ID=F.Friend_ID where Fr.salary > st.Salary order by fr.salary

  • + 0 comments

    Select name from (SELECT l.id,l.name as name,f.friend_id,p.salary from Students l Join Friends f on l.id = f.id JOIN Packages p on f.id = p.id where p.salary < (Select salary from Packages where id = f.friend_id) order by (Select salary from Packages where id = f.friend_id)) t;