Skip to content

Instantly share code, notes, and snippets.

View BenPrevel's full-sized avatar

BenPrevel BenPrevel

View GitHub Profile
@BenPrevel
BenPrevel / 06 - SQL avancé
Created December 15, 2021 18:03
06 - SQL avancé
Retourne le nom des équipes et le nombre de joueurs par équipe,
le tout classé par nombre de joueurs par équipe, de la plus nombreuse à la moins nombreuse.
mysql> SELECT team.name, count(*) as nbPlayer FROM player
JOIN team
ON team.id = player.team_id
GROUP BY team.name
ORDER BY count(*) DESC;
+------------+----------+
| name | nbPlayer |
@BenPrevel
BenPrevel / 05 - Les jointures
Last active December 15, 2021 14:19
05 - Les jointures
mysql> SELECT wizard.firstname, wizard.lastname, player.role, team.name FROM player
JOIN wizard ON wizard.id=player.wizard_id
JOIN team ON team.id=player.team_id
ORDER BY name ASC, role ASC, lastname ASC, firstname ASC;
+-------------+-----------------+--------+------------+
| firstname | lastname | role | name |
+-------------+-----------------+--------+------------+
| Sirius | Black | beater | Gryffindor |
| Lavender | Brown | beater | Gryffindor |
| Seamus | Finnigan | beater | Gryffindor |
@BenPrevel
BenPrevel / 03 - Manipulation des données
Created December 12, 2021 17:18
03 - Manipulation des données
mysql> INSERT INTO school (name, country, capacity) VALUES ('Beauxbatons Academy of Magic', 'France', 550), ('Castelobruxo', 'Brazil', 380), ('Durmstrang Institute', 'Norway', 570), ('Hogwarts School of Witchcraft and Wizardry', 'United Kingdom', 450), ('Ilvermorny School of Witchcraft and Wizardry', 'USA', 300), ('Koldovstoretz', 'Russia', 125), ('Mahoutokoro School of Magic', 'Japan', 800), ('Uagadou School of Magic', 'Uganda', 350);
Query OK, 8 rows affected (0,01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM school;
+----+----------------------------------------------+----------+----------------+
| id | name | capacity | country |
+----+----------------------------------------------+----------+----------------+
| 1 | Beauxbatons Academy of Magic | 550 | France |
| 2 | Castelobruxo | 380 | Brazil |
@BenPrevel
BenPrevel / 02 - Récupérer des informations avec SELECT
Created December 12, 2021 16:45
02 - Récupérer des informations avec SELECT
// Récupère tous les champs pour les sorciers nés entre 1975 et 1985
mysql> SELECT * FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31';
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| id | firstname | lastname | birthday | birth_place | biography | is_muggle |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| 1 | harry | potter | 1980-07-31 | london | | 0 |
| 2 | hermione | granger | 1979-09-19 | | Friend of Harry Potter | 0 |
| 4 | ron | weasley | 1980-03-01 | | Best friend of Harry | 0 |
| 5 | ginny | weasley | 1981-08-11 | | Sister of Ron and girlfriend of Harry | 0 |
@BenPrevel
BenPrevel / 01 - Introduction aux bases de données relationnelles
Created December 12, 2021 15:34
01 - Introduction aux bases de données relationnelles
mysql> SHOW TABLES;
+-------------------------+
| Tables_in_wild_db_quest |
+-------------------------+
| school |
| wizard |
+-------------------------+
2 rows in set (0,00 sec)
mysql> DESCRIBE wizard;
@BenPrevel
BenPrevel / Java 05 : Méthodes
Last active December 6, 2021 10:25
Java 05 : Méthodes
public class Decipherer {
public static String transcription(String message){
int key = message.length()/2;
String substring = message.substring (5, 5 + key);
String replace = substring.replace ("@#?"," ");
String reverseMessage = new StringBuilder(replace).reverse().toString();
return reverseMessage;
@BenPrevel
BenPrevel / Java 04 : Tableaux et itération
Created November 30, 2021 11:34
Java 04 : Tableaux et itération
public class Movies2 {
public static void main(String[] args) {
String [] movies = {"Indiana Jones and the Last Crusade", "Indiana Jones and the Temple of Doom", "Raiders of the Lost Ark"};
String [][] actorsMovies =
{{"Sean Connery", "Denholm Elliott", "Harrison Ford" },
{"Harrison Ford", "Kate Capshaw", "Jonathan Ke Quan"},
{"Harrison Ford", "Karen Allen", "Paul Freeman"}};
@BenPrevel
BenPrevel / Java 03 : Variables
Last active November 30, 2021 09:37
Java 03 : Variables
public class Variable {
public static void main(String[] args) {
String movieName = "Indiana Jones and the Last Crusade";
boolean haveSeen = true;
int releasedDate = 1989;
float movieRate = 8.2f;
System.out.println(movieRate);
public class CandyCount {
public static void main(String[] args) {
double money = 12.4;
double price = 1.2;
int candies = 0;
if (money > 0 && price > 0) {
while ((money - price) >= 0) {
candies = candies +1;
class Senpai{
public static void main(String[] args){
System.out.println("Notice me Senpai");
}
}