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 fnd as(
Select st.ID as ID, st.Name as Name, pk.Salary as Salary, f.Friend_ID, st1.Name as bf_name, pk1.Salary as bf_Sal
from Students st
join Packages pk on st.ID = pk.ID --- to get the student salary
join Friends f on st.ID = f.ID --- to get the best Friend ID
join Students st1 on st1.ID = f.Friend_ID -- to get the best friend Name
join Packages pk1 on f.Friend_ID = pk1.ID --- to get the best friend Salary
)
Select Name from fnd
where Salary < bf_Sal
order by bf_Sal
--- Name(output) < BestFriend (Salary offered)
--- order by best Salary asc
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 fnd as( Select st.ID as ID, st.Name as Name, pk.Salary as Salary, f.Friend_ID, st1.Name as bf_name, pk1.Salary as bf_Sal from Students st join Packages pk on st.ID = pk.ID --- to get the student salary join Friends f on st.ID = f.ID --- to get the best Friend ID join Students st1 on st1.ID = f.Friend_ID -- to get the best friend Name join Packages pk1 on f.Friend_ID = pk1.ID --- to get the best friend Salary )
Select Name from fnd where Salary < bf_Sal order by bf_Sal
--- Name(output) < BestFriend (Salary offered) --- order by best Salary asc