We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
with student_names as (
select s.id, s.name, p.salary
from students s
join packages p on s.id = p.id),
best_friends as(
select f.id as student_id, s.name as bff_name, s.id as bff_id, p.salary
from friends f
join students s on f.friend_id = s.id
join packages p on f.friend_id = p.id )
select sn.name
from student_names sn
join best_friends bf on sn.id = bf.student_id
where bf.salary > sn.salary
order by bf.salary
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Placements
You are viewing a single comment's thread. Return to all comments →
with student_names as ( select s.id, s.name, p.salary from students s join packages p on s.id = p.id), best_friends as( select f.id as student_id, s.name as bff_name, s.id as bff_id, p.salary from friends f join students s on f.friend_id = s.id join packages p on f.friend_id = p.id ) select sn.name from student_names sn join best_friends bf on sn.id = bf.student_id where bf.salary > sn.salary order by bf.salary