• + 0 comments

    with friend_sal as ( select f.id,f.friend_id,p.salary from friends f join packages p on f.friend_id = p.id
    ),stud_sal as ( select s.id,s.name,p1.salary from students s join packages p1
    on s.id = p1.id ) select ss.name from stud_sal ss join friend_sal fs ON ss.id = fs.id where fs.salary > ss.salary order by fs.salary