• + 0 comments
    with cte as (select s.*,f.Friend_ID,p.Salary as salary,p1.salary as best_friend_salary from Students s join Friends f on s.ID=f.ID
    join packages p on s.ID=p.ID 
    join packages p1 on f.Friend_ID=p1.ID
    where p1.salary>p.Salary)
    select Name from cte order by best_friend_salary