Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> SELECT count(wizard.id), team.name FROM wizard
- -> INNER JOIN player ON wizard.id=player.wizard_id
- -> INNER JOIN team ON player.team_id=team.id
- -> GROUP BY team.name
- -> GROUP BY count(wizard.id) DESC;
- +------------------+------------+
- | count(wizard.id) | name |
- +------------------+------------+
- | 36 | Gryffindor |
- | 21 | Slytherin |
- | 15 | Ravenclaw |
- | 12 | Hufflepuff |
- +------------------+------------+
- 4 rows in set (0.00 sec)
- mysql> SELECT COUNT(wizard.id), team.name FROM wizard
- -> INNER JOIN player ON wizard.id=player.wizard_id
- -> INNER JOIN team ON player.team_id=team.id
- -> GROUP BY team.name
- -> HAVING COUNT(wizard.id) >13
- -> ORDER BY name ASC;
- +------------------+------------+
- | count(wizard.id) | name |
- +------------------+------------+
- | 36 | Gryffindor |
- | 15 | Ravenclaw |
- | 21 | Slytherin |
- +------------------+------------+
- 3 rows in set (0.00 sec)
- mysql> SELECT DAYOFWEEK(enrollment_date), CONCAT(firstname, ' ', lastname) AS fullname from wizard
- -> JOIN player ON wizard.id=player.wizard_id
- -> JOIN team ON player.team_id=team.id
- -> WHERE DAYOFWEEK(enrollment_date)=2 AND name="Gryffindor"
- -> ORDER BY enrollment_date;
- +----------------------------+----------------------+
- | DAYOFWEEK(enrollment_date) | fullname |
- +----------------------------+----------------------+
- | 2 | George Weasley |
- | 2 | Alice Longbottom |
- | 2 | Cadogan |
- | 2 | Godric Gryffindor |
- | 2 | Sirius Black |
- | 2 | Aberforth Dumbledore |
- | 2 | Augusta Longbottom |
- +----------------------------+----------------------+
- 7 rows in set (0.00 sec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement