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 cte AS(
SELECT S.ID AS student_id,
S.Name AS student_name,
f.friend_id AS friend_id,
ps.salary AS student_salary,
ps.id AS s_id,
pf.salary AS friend_salary,
pf.id AS f_id
FROM Students S
JOIN Friends f
ON S.ID = F.ID
JOIN Packages ps
ON ps.id = s.id
JOIN Packages pf
ON pf.id = f.friend_id
order by 1)
SELECT student_name
FROM cte
WHERE friend_salary > student_salary
order by friend_salary
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Placements
You are viewing a single comment's thread. Return to all comments →
WITH cte AS( SELECT S.ID AS student_id, S.Name AS student_name, f.friend_id AS friend_id, ps.salary AS student_salary, ps.id AS s_id, pf.salary AS friend_salary, pf.id AS f_id FROM Students S JOIN Friends f ON S.ID = F.ID JOIN Packages ps ON ps.id = s.id JOIN Packages pf ON pf.id = f.friend_id order by 1) SELECT student_name FROM cte WHERE friend_salary > student_salary order by friend_salary