Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> SELECT team.name , COUNT(player.id) AS total FROM player JOIN team ON player.team_id = team.id GROUP BY team.id ORDER BY total DESC;
- +------------+-------+
- | name | total |
- +------------+-------+
- | Gryffindor | 36 |
- | Slytherin | 21 |
- | Ravenclaw | 15 |
- | Hufflepuff | 12 |
- +------------+-------+
- 4 rows IN SET (0.01 sec)
- mysql> SELECT team.name , COUNT(player.id) AS total FROM player JOIN team ON player.team_id = team.id GROUP BY team.id HAVING total >=14 ORDER BY team.name;
- +------------+-------+
- | name | total |
- +------------+-------+
- | Gryffindor | 36 |
- | Ravenclaw | 15 |
- | Slytherin | 21 |
- +------------+-------+
- 3 rows IN SET (0.01 sec)
- mysql> SELECT wizard.firstname,team.name,enrollment_date FROM player JOIN team ON player.team_id = team.id JOIN wizard ON player.wizard_id = wizard.id WHERE team.name = "Gryffindor" AND DAYOFWEEK(enrollment_date)= 2 ORDER BY enrollment_date;
- +------------+------------+-----------------+
- | firstname | name | enrollment_date |
- +------------+------------+-----------------+
- | Weasley | Gryffindor | 1991-08-26 |
- | Longbottom | Gryffindor | 1992-02-17 |
- | | Gryffindor | 1993-01-04 |
- | Gryffindor | Gryffindor | 1993-08-30 |
- | Black | Gryffindor | 1994-01-10 |
- | Dumbledore | Gryffindor | 1995-04-24 |
- | Longbottom | Gryffindor | 1999-10-25 |
- +------------+------------+-----------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement