Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.96 KB | None | 0 0
  1. SELECT people1.ID, people1.name
  2. FROM People people1,
  3. GROUP BY people1.ID -- Can probably skip this?
  4. HAVING 0 < COUNT(--For each person, counts how many times they did not have the worst score for each sport
  5.     SELECT *
  6.     FROM
  7.         (SELECT results1.sportID, MAX(results1.RESULT)
  8.         FROM Results results1,
  9.         WHERE results.peopleID == people1.ID
  10.         GROUP BY results1.sportID) AS personBest, -- For each person, creates a table with his best score for each sport
  11.         (SELECT results1.sportID, MIN(results1.RESULT)
  12.         FROM Results results1
  13.         WHERE results1.sportID IN
  14.             (SELECT UNIQUE results.sportID
  15.             FROM Results results
  16.             WHERE results.peopleID == people1.ID)
  17.         GROUP BY results1.sportID) AS sportWorst -- For each person, creates a table with the worst score for each sport the person played in
  18.     WHERE sportWorst.sportID = personBest.sportID AND sportWorst.RESULT != personBest.RESULT
  19.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement