• + 1 comment
    with a as (select f.ID ID,f.Friend_ID F_ID,p1.salary as id_salary,p2.salary as friend_salary
    from friends f
    join packages p1 on f.ID=p1.ID
    join packages p2 on f.Friend_ID = p2.ID)
    select b.Name 
    from Students b
    join a on a.ID=b.ID
    where a.friend_salary>a.id_salary
    order by a.friend_salary;