DUET PG Score Card 2021
NHAI Recruitment 2021
Bihar Board 12th Dummy Admit Card 2022
RBI Assistant Notification 2021
Jee Advanced 2021 Result
NIACL Assistant Recruitment 2021
SBI PO Online Form 2021

Students, Friends and Packages. Students contains two columns: ID and Name

You are given three tables: Students, Friends and Packages. Students contains two columns: ID and NameFriends 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).

Students, Friends and Packages. Students contains two columns: ID and Name.

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

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).
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).

Sample Output

Samantha
Julia
Scarlet


Explanation

See the following table:

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).

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 Students, Friends and Packages

Solution

CREATE TABLE students (id int, NAME VARCHAR(30));
CREATE TABLE packages (id int, salary INT);
CREATE TABLE friends (id int, friend_id INT);

INSERT INTO students values (1,'Ashley');
INSERT INTO students values (2,'Samantha');
INSERT INTO students values (3,'Julia');
INSERT INTO students values (4,'Scarlet');

INSERT INTO packages values (1,15.20);
INSERT INTO packages values (2,10.06);
INSERT INTO packages values (3,11.55);
INSERT INTO packages values (4,12.12);

INSERT INTO friends values (1,2);
INSERT INTO friends values (2,3);
INSERT INTO friends values (3,4);
INSERT INTO friends values (4,1);

SELECT * FROM students
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).
Students, Friends and Packages. Students contains two columns: ID and Name 1 SpeedJobAlert
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).
Students, Friends and Packages. Students contains two columns: ID and Name 2 SpeedJobAlert
select s.name from students s, friends f, packages p, packages p2 where s.id = f.id and f.friend_id = p2.id and s.id = p.id and p.salary < p2.salary order by p2.salary;

ORACLE Live SQL: https://livesql.oracle.com/apex/f?p=590:1000

Download Source Code: 👇

Candidates having any kind of query so he/she can ask in our comment section. Our Panel will b reverting back as soon as possible. Thank You. For more details visit our website (https://speedjobalert.com/)

Leave a Comment