• + 0 comments

    with cte_cal as ( select f.id, P.salary, dp.id as friendid, dp.salary as friedsal, s.name as name from Friends F INNER JOIN Packages P ON P.id = F.ID INNER JOIN Packages dP ON dP.id = F.Friend_ID INNER JOIN Students S ON S.id = P.id )

    select name from cte_cal where salary < friedsal order by friedsal ASC