Skip to content

Instantly share code, notes, and snippets.

@gyommy
Created November 29, 2021 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyommy/fde7e3e0d57be10024418877b7bd92fa to your computer and use it in GitHub Desktop.
Save gyommy/fde7e3e0d57be10024418877b7bd92fa to your computer and use it in GitHub Desktop.
Quete subqueries
-- Question 1 :
SELECT `first_name`, `last_name`
FROM `wizard`
WHERE wizard.id IN (
SELECT `wizard_id`
FROM `player`
WHERE `enrollment_date`
BETWEEN '1995-01-01' AND '1998-12-31'
);
-- Question 2 :
SELECT `first_name`, `last_name`
FROM `wizard`
WHERE wizard.id IN (
SELECT `wizard_id`
FROM `player`
WHERE `enrollment_date`
BETWEEN '1995-01-01' AND '1998-12-31'
AND `role` = 'seeker'
);
-- Question 3 :
SELECT `first_name`, `last_name`, `role`
FROM `wizard` INNER JOIN `player`
ON wizard.id = wizard_id
WHERE wizard.id IN (
SELECT `wizard_id`
FROM `player`
WHERE `enrollment_date`
BETWEEN '1995-01-01' AND '1998-12-31'
AND `role` = 'chaser'
);
-- Question 4 :
CREATE OR REPLACE VIEW role_team AS (
SELECT `role`, team.name, count(wizard_id) as N_players
FROM `player`, `team`
WHERE team.id = player.id
GROUP BY team.name
);
SELECT * from role_team;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment