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 Stds.ID,Stds.Name,Frnd.Friend_ID as Best_Friend_ID,
Pk.Salary as Student_Salary,
BFPk.Salary as Bestfriend_Salary
from students Stds
inner join Friends Frnd on Stds.ID = Frnd.ID
inner join Packages PK on Pk.ID = Stds.ID
inner join Packages BFPk on BFPk.ID = Frnd.Friend_ID),
CTE_2 as (
select
case When Bestfriend_Salary > Student_Salary Then Name
end as bfmorethanstudent,Bestfriend_Salary
from CTE)
select bfmorethanstudent from CTE_2
where bfmorethanstudent is not null
order by Bestfriend_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 CTE as (select Stds.ID,Stds.Name,Frnd.Friend_ID as Best_Friend_ID, Pk.Salary as Student_Salary, BFPk.Salary as Bestfriend_Salary from students Stds inner join Friends Frnd on Stds.ID = Frnd.ID inner join Packages PK on Pk.ID = Stds.ID inner join Packages BFPk on BFPk.ID = Frnd.Friend_ID), CTE_2 as ( select case When Bestfriend_Salary > Student_Salary Then Name end as bfmorethanstudent,Bestfriend_Salary from CTE) select bfmorethanstudent from CTE_2 where bfmorethanstudent is not null order by Bestfriend_Salary