Sort by

recency

|

1784 Discussions

|

  • + 0 comments

    With cte as(

    select f.id,f.friend_id,s.name,p.Salary from friends as f Left join students as s on f.id=s.id Left join Packages as p on f.id=p.id ), cte2 as( select distinct c1.salary,c2.name from cte as c1 join cte as c2 on c1.id=c2.friend_id where c1.salary>c2.salary

    )

    select name from cte2 order by salary asc

  • + 0 comments

    My SQL:

    select s.name from (
    select f.id, f.friend_id, p1.Salary my_salary from friends f
    inner join packages p1
    on f.id = p1.id
    ) a
    inner join 
    (
    select f.id, f.friend_id, p1.Salary friend_salary from friends f
    inner join packages p1
    on f.friend_id = p1.id
    ) b
    on a.id = b.id
    inner join students s
    on s.id = a.id
    where a.my_salary < b.friend_salary
    order by b.friend_salary
    
  • + 0 comments

    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 p2.id=f.friend_id where p2.salary > p1.salary order by p2.salary;

  • + 0 comments
    with temp as (
    select students.id as student_id
    , name
    , friend_id
    , p1.salary as student_salary
    , p2.salary as friend_salary
    from students
    left join friends on students.id = friends.id
    left join packages as p1 on students.id = p1.id
    left join packages as p2 on friends.friend_id = p2.id)
    select name
    from temp
    where friend_salary > student_salary
    order by friend_salary 
    
  • + 1 comment

    MY SQL

    SELECT NAME FROM STUDENTS S, FRIENDS F, PACKAGES P1, PACKAGES P2 
    WHERE
    S.ID=F.ID AND S.ID=P1.ID AND F.FRIEND_ID=P2.ID AND P1.SALARY < P2.SALARY
    ORDER BY P2.SALARY;