Skip to content

Instantly share code, notes, and snippets.

@Satori-i
Created December 12, 2019 18:23
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 Satori-i/c00f12e0c4702affc94f2f9a9d0b4052 to your computer and use it in GitHub Desktop.
Save Satori-i/c00f12e0c4702affc94f2f9a9d0b4052 to your computer and use it in GitHub Desktop.
Potterquid
mysql> SELECT t.name, count(*) AS nb_student FROM team t JOIN player p ON t.id = p.team_id GROUP BY name ORDER BY nb_student DESC;
+------------+------------+
| name | nb_student |
+------------+------------+
| Gryffindor | 36 |
| Slytherin | 21 |
| Ravenclaw | 15 |
| Hufflepuff | 12 |
+------------+------------+
4 rows in set (0.00 sec)
mysql> SELECT t.name FROM team t JOIN player p ON t.id = p.team_id GROUP BY name HAVING count(*) >= 14 ORDER BY name;
+------------+
| name |
+------------+
| Gryffindor |
| Ravenclaw |
| Slytherin |
+------------+
3 rows in set (0.00 sec)
mysql> select w.lastname, w.firstname from wizard w
-> join player p
-> on w.id = p.wizard_id
-> join team t
-> on t.id = p.team_id
-> where t.name ="Gryffindor" and dayofweek(p.enrollment_date) = 2
-> order by p.enrollment_date;
+------------+-----------+
| lastname | firstname |
+------------+-----------+
| Weasley | George |
| Longbottom | Alice |
| | Cadogan |
| Gryffindor | Godric |
| Black | Sirius |
| Dumbledore | Aberforth |
| Longbottom | Augusta |
+------------+-----------+
7 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment