0% found this document useful (0 votes)
11 views9 pages

Evaluation de Base de Donnees

The document contains SQL exercises related to database evaluations, focusing on various SQL commands such as SELECT, GROUP BY, HAVING, and JOIN. It includes multiple queries that analyze employee data, sales, and product information. The exercises are structured to demonstrate the application of SQL functions and aggregations in different scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

Evaluation de Base de Donnees

The document contains SQL exercises related to database evaluations, focusing on various SQL commands such as SELECT, GROUP BY, HAVING, and JOIN. It includes multiple queries that analyze employee data, sales, and product information. The exercises are structured to demonstrate the application of SQL functions and aggregations in different scenarios.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

NOM: OUATTARA

Prénom: KOUAME HOUSSEINI

Classe: Master 2 SRT HETEC

GMAIL: [email protected]

Évaluation de Base de données Orales

Exercice 1 page 34 page 3 a 6 ( groupe BY)


3
SELECT CodP, COUNT(*)
FROM PC
GROUP BY CodP;

4
SELECT CodC, NumC, DATC
FROM Commande
ORDER BY CodC, DATC DESC;

5
SELECT CodC, SUM(COALESCE(MontF, 0))
FROM Facture
GROUP BY CodC;
SELECT CodC, SUM(MontF)
FROM Facture
GROUP BY CodC;

6
SELECT NumC, COUNT(*)
FRON PC
GROUP BY Numc;

II. Page 35 Partie (HAVING )question 1 a 6


1
SELECT CodP, SUM(QteC)
FROM PC
GROUP BY CodP
HAVING SUM(QteC) > 10;

2
SELECT CodP, AVG(QteC)
FROM PC
GROUP BY CodP
HAVING AVG(QteC) > 50;

3
SELECT CodC, COUNT(*)
FROM Commande
GROUP BY CodC
HAVING COUNT(*) > 2;

4
SELECT COUNT(*)
FROM Produit
WHERE PU > (
SELECT AVG(PU) FROM Produit
);

5
SELECT CodC, SUM(MontF)
FROM Facture
WHERE EXTRACT(YEAR FROM DATF) = 2014
GROUP BY CodC
HAVING SUM(MontF) > 1000;

6
SELECT COUNT(*)
FROM PC
WHERE CodP = 2
AND NumC IN (
SELECT NumC
FROM PC
GROUP BY NumC
HAVING COUNT(*) > 10) ;
Page 39 exo 1 a 7
1- SELECT
e.first_name AS prenom,
e.salary AS salaire,
j.job_title AS travail,
d.department_name AS departement
FROM
employees e
JOIN
jobs j ON e.job_id = j.job_id
JOIN
departments d ON e.department_id = d.department_id
ORDER BY
e.salary DESC;

2
SELECT
c.country_name AS pays,
COUNT(e.employee_id) AS nombre_employes,
SUM(e.salary) AS masse_salaire
FROM
employees e
JOIN
departments d ON e.department_id = d.department_id
JOIN
locations l ON d.location_id = l.location_id
JOIN
countries c ON l.country_id = c.country_id
JOIN
regions r ON c.region_id = r.region_id
WHERE
r.region_name = 'Europe'
GROUP BY
c.country_name
ORDER BY
masse_salaire DESC;

3
SELECT
d.department_name AS departement,
l.street_address AS adresse,
l.city AS ville,
COUNT(e.employee_id) AS nombre_employes_commission
FROM
departments d
JOIN
locations l ON d.location_id = l.location_id
JOIN
employees e ON d.department_id = e.department_id
WHERE
e.commission_pct IS NOT NULL
AND e.commission_pct > 0
GROUP BY
d.department_name, l.street_address, l.city
ORDER BY
nombre_employes_commission DESC;

SELECT
e.first_name AS "Prénom",
e.last_name AS "Nom",
r.region_id AS "N° région",
r.region_name AS "Région",
c.country_name AS "Pays",
l.city AS "Ville"
FROM
employees e
JOIN departments d ON e.department_id = d.department_id
JOIN locations l ON d.location_id = l.location_id
JOIN countries c ON l.country_id = c.country_id
JOIN regions r ON c.region_id = r.region_id
ORDER BY r.region_name, e.last_name;

5- SELECT
d.department_id AS "N° Dépt",
d.department_name AS "Département",
e.first_name || ' ' || e.last_name AS "Employé",
j.job_title AS "Poste",
l.city AS "Ville"
FROM
employees e
JOIN departments d ON e.department_id = d.department_id
JOIN jobs j ON e.job_id = j.job_id
JOIN locations l ON d.location_id = l.location_id
JOIN countries c ON l.country_id = c.country_id
WHERE c.country_name = 'France'
ORDER BY d.department_id, e.last_name;

6-

SELECT
j.job_title AS "Poste",
MIN(e.salary) AS "Salaire min",
MAX(e.salary) AS "Salaire max",
MAX(e.salary) - MIN(e.salary) AS "Écart salarial",
ROUND(AVG(e.salary), 2) AS "Moyenne"
FROM
employees e
JOIN departments d ON e.department_id = d.department_id
JOIN jobs j ON e.job_id = j.job_id
WHERE d.department_name = 'Administration'
GROUP BY j.job_title
ORDER BY "Écart salarial" DESC;
5- SELECT
d.department_id AS "N° Dépt",
d.department_name AS "Département",
e.first_name || ' ' || e.last_name AS "Employé",
j.job_title AS "Poste",
l.city AS "Ville"
FROM
employees e
JOIN departments d ON e.department_id = d.department_id
JOIN jobs j ON e.job_id = j.job_id
JOIN locations l ON d.location_id = l.location_id
JOIN countries c ON l.country_id = c.country_id
WHERE c.country_name = 'France'
ORDER BY d.department_id, e.last_name;

7- SELECT
e.first_name,
e.last_name,
EXTRACT(YEAR FROM AGE(CURRENT_DATE, e.birth_date)) AS age,
j.job_title,
d.department_name
FROM
employees e
/* mêmes jointures */
WHERE
j.job_title = 'Finance Manager'
AND l.city = 'Washington'
AND EXTRACT(YEAR FROM AGE(CURRENT_DATE, e.birth_date))
BETWEEN 20 AND 50;

You might also like