Created
December 9, 2018 07:35
-
-
Save afrida67/d857daa5978022d27da98bed5325a52b to your computer and use it in GitHub Desktop.
Placements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
Oracle Solution | |
*/ | |
Select name from | |
(select t1.name, t2.friend_id, t3.salary | |
from students t1 inner join friends t2 on t1.id = t2.id | |
inner join packages t3 on t1.id = t3.id ) new1 | |
inner join packages t4 on t4.id = new1.friend_id | |
where new1.salary < t4.salary | |
order by t4.salary; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment