• + 0 comments

    with all_friends as (SELECT s.Name, f.ID, f.Friend_ID, p.Salary AS person_salary, pg.Salary AS friend_salary FROM Students s INNER JOIN Friends f ON s.ID = f.ID INNER JOIN Packages p ON s.ID = p.ID INNER JOIN Packages pg ON f.Friend_ID = pg.ID friend's salary WHERE pg.Salary > p.Salary ORDER BY pg.Salary ASC) SELECT Name FROM all_friends;