• + 0 comments

    with required_table as ( select s.id,s.name,friend_id as bf,salary from students s join friends f on s.id = f.id join packages p on s.id = p.id ) select t1.name from required_table t1 join required_table t2 on t1.bf = t2.id where t2.salary > t1.salary order by t2.salary