• + 0 comments

    with first as ( select s.Name,p.Salary,f.ID,f.Friend_ID from Students s Join Friends f on s.ID=f.ID join Packages p on p.ID=f.ID ), second as (

    select p1.Salary as Friends_salary,f1.id from Friends f1 join Packages p1 on f1.Friend_ID=p1.ID)

    select first.name from first join second On first.ID=second.id where first.salary