# Placements Solution

Hello Friends in this article i am gone to share Hacker Rank SQL Solutions with you | Placements Solution

Also Visit:ย  SQL Project Planning Solution

#### Problem

You are given threeย tables:ย Students,ย Friendsย andย Packages.ย Studentsย contains two columns:ย IDย andย Name.ย Friendsย contains two columns:ย IDย andย Friend_IDย (IDย of the ONLY best friend).ย Packagesย contains two columns:ย IDย andย Salaryย (offered salary in \$ย thousandsย per month).

Write a query to output the names of those students whoseย best friends got offered a higher salary than them. Names must be ordered by the salary amount offered to the best friends. It is guaranteed that no two students got same salary offer.

Sample Input

Sample Output

```Samantha
Julia
Scarlet```

Explanation

Now,

• Samanthaโsย best friend got offered a higher salary than her at 11.55
• Juliaโsย best friend got offered a higher salary than her at 12.12
• Scarletโsย best friend got offered a higher salary than her at 15.2
• Ashleyโsย best friend did NOT get offered a higher salary than her

The name output, when ordered by the salary offered to their friends, will be:

• Samantha
• Julia
• Scarlet

## Solution โ Placements

##### MySQL Code
```selectย temp1.sn
fromย (selectย S.IDย si,S.Nameย sn,P.Salaryย psย fromย Studentsย Sย joinย Packagesย Pย onย S.ID=P.ID)ย
temp1ย joinย (selectย FF.IDย fi,FF.Friend_IDย fd,PP.Salaryย ppsย fromย Friendsย
FFย joinย Packagesย PPย onย FF.Friend_ID=pp.ID)ย temp2ย onย temp1.si=temp2.fiย andย temp1.ps<temp2.pps
orderย byย temp2.ppsย asc;
```

Disclaimer: The above Problems are generated by Hacker Rank but the Solutions are Provided by NYANDER.COM. All Hacker Rank SQL Solutions Shared only for Educational and Learning Purpose.