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 cte1 as(
SELECT
s.id as id,
s.name as name,
p.salary as salary,
f.friend_id as friend_id
FROM Students s JOIN Friends f
ON s.id = f.id
JOIN packages p
ON s.id = p.id)
SELECT
c1.name as main_name
FROM cte1 c1 JOIN students s1
ON c1.friend_id = s1.id
JOIN packages p2
ON p2.id = s1.id
WHERE p2.salary > c1.salary
ORDER BY p2.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 cte1 as( SELECT s.id as id, s.name as name, p.salary as salary, f.friend_id as friend_id FROM Students s JOIN Friends f ON s.id = f.id JOIN packages p ON s.id = p.id) SELECT c1.name as main_name FROM cte1 c1 JOIN students s1 ON c1.friend_id = s1.id JOIN packages p2 ON p2.id = s1.id WHERE p2.salary > c1.salary ORDER BY p2.salary;