Skip to content

Instantly share code, notes, and snippets.

@clemderome
Last active June 18, 2020 16:54
Show Gist options
  • Save clemderome/37b6e8e6112e2603ed91d153b9fa17f6 to your computer and use it in GitHub Desktop.
Save clemderome/37b6e8e6112e2603ed91d153b9fa17f6 to your computer and use it in GitHub Desktop.
mysql> SELECT t.name, COUNT(*) AS nb_players
FROM player p JOIN team t ON t.id = p.team_id
GROUP BY team_id
ORDER BY nb_players DESC;
+------------+------------+
| name | nb_players |
+------------+------------+
| Gryffindor | 36 |
| Slytherin | 21 |
| Ravenclaw | 15 |
| Hufflepuff | 12 |
+------------+------------+
4 rows in set (0,01 sec)
mysql> SELECT t.name, COUNT(*) AS nb_players
FROM player p
JOIN team t ON t.id = p.team_id
GROUP BY team_id
HAVING nb_players >= 14
ORDER BY name ASC;
+------------+------------+
| name | nb_players |
+------------+------------+
| Gryffindor | 36 |
| Ravenclaw | 15 |
| Slytherin | 21 |
+------------+------------+
3 rows in set (0,01 sec)
mysql> SELECT CONCAT(w.firstname, ' ', w.lastname) AS monday_players
FROM player p
JOIN wizard w ON w.id = p.wizard_id
WHERE DAYOFWEEK(enrollment_date) = 2 AND team_id = 1
ORDER BY enrollment_date ASC;
+----------------------+
| monday_players |
+----------------------+
| George Weasley |
| Alice Longbottom |
| Cadogan |
| Godric Gryffindor |
| Sirius Black |
| Aberforth Dumbledore |
| Augusta Longbottom |
+----------------------+
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