Compare commits

..

4 Commits

Author SHA1 Message Date
57ff62f3c9 Mise à jour du Makefile pour corriger les chemins des fichiers journaux et ajouter la cible tp2 2025-09-25 09:44:00 +02:00
fc656b2c2c Ajout de nouvelles requêtes SQL pour les analyses de données dans TP1.sql 2025-09-25 09:43:30 +02:00
615261961a Add MySQL setup and initial data scripts
- Created a Docker Compose file to set up a MySQL container named M2_SQL_COURSE with an empty password and a database named TP.
- Added a Makefile with a target to execute a SQL script (TP1.sql) inside the MySQL container and log the output.
- Implemented the TP1.sql script to create tables for Magasin and Localite, insert initial data, and perform several queries.
2025-09-25 09:31:10 +02:00
a2760c7fa2 Ajout des fichiers journaux au .gitignore 2025-09-25 09:30:53 +02:00
5 changed files with 246 additions and 1434 deletions

3
.gitignore vendored
View File

@@ -10,3 +10,6 @@
*.pdf
.ipynb_checkpoints
*.log
logs

File diff suppressed because it is too large Load Diff

7
M2/SQL/Makefile Normal file
View File

@@ -0,0 +1,7 @@
# Makefile
tp1:
docker exec -i M2_SQL_COURSE mysql -u root TP -t < ./scripts/TP1.sql | tee logs/tp1.log
tp2:
docker exec -i M2_SQL_COURSE mysql -u root TP -t < ./scripts/TP2.sql | tee logs/tp2.log

13
M2/SQL/docker-compose.yml Normal file
View File

@@ -0,0 +1,13 @@
services:
mysql:
container_name: M2_SQL_COURSE
image: mysql:latest
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
MYSQL_DATABASE: TP
volumes:
- mysql_data:/var/lib/mysql
restart: unless-stopped
volumes:
mysql_data:

71
M2/SQL/scripts/TP1.sql Normal file
View File

@@ -0,0 +1,71 @@
DROP TABLE IF EXISTS Magasin;
DROP TABLE IF EXISTS Localite;
-- Q1.1
CREATE TABLE IF NOT EXISTS Magasin(
Id VARCHAR(3) PRIMARY KEY,
Enseigne VARCHAR(100) NOT NULL,
Ville VARCHAR(255) NOT NULL,
Chiffre INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS Localite(
Ville VARCHAR(255) NOT NULL,
Population INTEGER NOT NULL
);
INSERT INTO Localite (Ville, Population) VALUES
('Créteil', 92984),
('Pantin', 60597),
('Colombes', 87328);
INSERT INTO Magasin (Id, Enseigne, Ville, Chiffre) VALUES
('D10', 'Super Discount', 'Créteil', 2800000),
('I10', 'Inter Prix', 'Créteil', 1230000),
('T01', 'Leader Trade', 'Créteil', 830000),
('M01', 'Discount Market', 'Créteil', 1010000),
('T08', 'Leader Trade', 'Pantin', 3230000),
('D20', 'Super Discount', 'Pantin', 556000),
('D22', 'Super Discount', 'Colombes', 4032000),
('T05', 'Leader Trade', 'Colombes', 2780000),
('I17', 'Inter Prix', 'Colombes', 3912000),
('M87', 'Discount Market', 'Colombes', 1471000),
('M89', 'Discount Market', 'Colombes', 845000);
SELECT * FROM Magasin;
SELECT * FROM Localite;
-- Q1.2
SELECT Ville, COUNT(*) AS NombreMagasins
FROM Magasin
GROUP BY Ville
ORDER BY Ville ASC;
-- Q1.3
SELECT Ville, Enseigne, COUNT(*) as NombreMagasins
FROM Magasin
GROUP BY Ville, Enseigne
HAVING NombreMagasins >= 2;
-- Q1.4
SELECT Enseigne, Ville, AVG(Chiffre) AS ChiffreMoyen
FROM Magasin
GROUP BY Enseigne, Ville;
-- Q1.5
SELECT Enseigne, m.Ville, AVG(Chiffre) AS ChiffreMoyen
FROM Magasin AS m
JOIN Localite AS l ON m.Ville = l.Ville
WHERE l.Population >= 80000
GROUP BY Enseigne, m.Ville;
-- Q1.6
SELECT Enseigne, Ville, SUM(Chiffre) as ChiffreAffaire
FROM Magasin
GROUP BY Ville, Enseigne;
-- Q1.7
SELECT Enseigne, Ville, SUM(Chiffre) as ChiffreAffaire
FROM Magasin
GROUP BY Ville, Enseigne
HAVING ChiffreAffaire >= 1000000;