• + 0 comments

    with CTE as (select s.id, s.name, p.salary as salary, f.friend_ID, p2.salary as salary_2 from Students s join friends f on f.id=s.id join Packages p on p.ID= s.id join packages p2 on f.Friend_ID = p2.id) select name from CTE where salary_2>salary order by salary_2;