Skip to content

Instantly share code, notes, and snippets.

@shojibMahabub
Created December 5, 2018 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shojibMahabub/42e88e21c23c75a2953005eb68ea3848 to your computer and use it in GitHub Desktop.
Save shojibMahabub/42e88e21c23c75a2953005eb68ea3848 to your computer and use it in GitHub Desktop.
database query for problem 4
Explanation:
--------------
In order to get the result,
I joined packages to get student's salaries. and joined friends
to get ID. For getting Friends salary I joined Packages once again.
Then I compared between salaries to find the students.
After that I ordered them by salary.
QUERY:
---------------
SELECT s.Name FROM Students AS s
JOIN Packages AS sp ON s.ID = sp.ID
JOIN Friends AS f ON s.ID = f.ID
JOIN Packages AS fp ON f.Friend_ID = fp.ID
WHERE sp.Salary < fp.Salary
ORDER BY fp.Salary;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment