0% found this document useful (0 votes)
3 views

Corrigé TP2_SQL(partie1)

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)
3 views

Corrigé TP2_SQL(partie1)

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/ 6

EPI Sousse

Abir ZEKRI BEN YAHIA

Correction TP N° 2

Exercice N° 1 :

//Q1

select Num_Emp,Nom_Emp

from EMPLOYE

where Num_Dep=20

//Q2

select Num_Emp,Nom_Emp,Num_Dep

from EMPLOYE

where Fonction_Emp='ouvrier'

//Q3

select Nom_Emp

from EMPLOYE

where Fonction_Emp='vendeur' and Num_Dep=30 and Salaire_Emp>1500

//Q4

select Nom_Emp,Fonction_Emp,Salaire_Emp

from EMPLOYE

where Fonction_Emp='President' or Fonction_Emp='Directeur'

//Q5

select Nom_Emp,Fonction_Emp,Salaire_Emp

from EMPLOYE

where (Fonction_Emp='President' or Fonction_Emp='Directeur') and Salaire_Emp>5000

//Q6

select Nom_Emp,Fonction_Emp

from EMPLOYE

where (Fonction_Emp='Directeur' and Num_Dep=10) or (Fonction_Emp='Ouvrier' and


Num_Dep=20)

//Q7
select Nom_Emp,Fonction_Emp,Num_Dep
EPI Sousse
Abir ZEKRI BEN YAHIA

from EMPLOYE

where Fonction_Emp not in ('ouvrier','directeur')

//Q8

select Nom_Emp,Fonction_Emp,Salaire_Emp

from EMPLOYE

where Salaire_Emp between 2200 and 2800

//Q9

select Nom_Emp,Fonction_Emp,Num_Dep

from EMPLOYE

where Fonction_Emp in ('ouvrier','directeur','secrétaire')

//Q10

select *

from EMPLOYE

where Sup_Emp is not null

//Q11

select *

from EMPLOYE

where Sup_Emp is null

//Q12

select Salaire_Emp,Fonction_Emp,Nom_Emp

from EMPLOYE

where Num_Dep=20

order by Salaire_Emp

//Q13

select Salaire_Emp,Fonction_Emp,Nom_Emp

from EMPLOYE

where Num_Dep=20

order by Salaire_Emp desc


//Q14
EPI Sousse
Abir ZEKRI BEN YAHIA

select *

from EMPLOYE

order by Fonction_Emp asc,Salaire_Emp desc

//Q15

select AVG(Salaire_Emp) as "Moyenne des salaires"

from EMPLOYE

//Q16

select AVG(Salaire_Emp) as "Moyenne des salaires des ouvriers"

from EMPLOYE

where Fonction_Emp='ouvrier'

//Q17

select MAX(Salaire_Emp) as "Salaire Max",MIN(Salaire_Emp) as "Salaire Min"

from EMPLOYE

//Q18

select COUNT(*) as "Nombre d'Employés du département 10"

from EMPLOYE

where Num_Dep=10

//Q19

select COUNT(distinct(Fonction_Emp)) as "Nombre de fonctions"

from EMPLOYE

where Num_Dep=10

//Q20

select Num_Dep,AVG(Salaire_Emp) as "Moyenne de salaires"

from EMPLOYE

group by Num_Dep

//Q21

select Num_Dep, AVG(Salaire_Emp*12) as "Salaire annuel moyen"

from EMPLOYE
where Fonction_Emp not in ('directeur','president')
EPI Sousse
Abir ZEKRI BEN YAHIA

group by Num_Dep

//Q22

select Num_Dep,Fonction_Emp,COUNT(Num_Emp) as "Nombre


d'employés",AVG(Salaire_Emp) as "Salaire Moyen"

from EMPLOYE

group by Num_Dep,Fonction_Emp

//Q23

select Fonction_Emp,AVG(Salaire_Emp) as "Salaire Moyen"

from EMPLOYE

group by Fonction_Emp

having COUNT(Num_Emp)>2

//Q24

select Num_Dep

from EMPLOYE

where Fonction_Emp='secrétaire'

group by Num_Dep

having COUNT(Nom_Emp)>=2

Exercice N° 3 :

1)

2)

3)
4) SELECT *
FROM employees

WHERE department_id IS NULL;


5) SELECT first_name || ' ' || last_name as Full_Name, hire_date,
salary, department_id
FROM employees
WHERE first_name NOT LIKE '%M%'

ORDER BY department_id;
6) SELECT *
EPI Sousse
Abir ZEKRI BEN YAHIA

FROM employees
WHERE salary BETWEEN 8000 AND 12000
AND commission_pct IS NOT NULL
OR department_id NOT IN (40 , 120 , 70)

AND hire_date < '2003-06-05'


7) SELECT first_name ||' '||last_name AS Full_Name, salary
FROM employees

WHERE commission_pct IS NULL;


8) SELECT first_name ||' '||last_name AS Full_Name,
phone_number ||' - '|| email AS Contact_Details,
salary AS Remuneration
FROM employees

WHERE salary BETWEEN 9000 AND 17000;


9) SELECT first_name, last_name, salary
FROM employees

WHERE first_name LIKE '%m';


10)
 SELECT concat(first_name,last_name) as Name, salary
FROM employees
WHERE salary NOT BETWEEN 7000 AND 15000

ORDER BY first_name || ' ' || last_name;


 SELECT first_name || ' ' || last_name as Name, salary
FROM employees
WHERE salary NOT BETWEEN 7000 AND 15000

ORDER BY first_name || ' ' || last_name;


11) SELECT first_name ||' '||last_name AS Full_Name, job_id, hire_date
FROM employees
WHERE hire_date BETWEEN '2007-11-05' AND '2009-07-05';
12) SELECT first_name ||' '|| last_name AS Full_Name, department_id
FROM employees
WHERE department_id = 70
OR department_id = 90;
13) SELECT first_name ||' '||last_name AS Full_Name, salary, manager_id FROM em
ployeesWHERE manager_id IS NOT NULL;
14) SELECT first_name, last_name, email, salary, manager_id FROM employees
WHERE manager_id IN (120 , 103 , 145);
15) SELECT *
EPI Sousse
Abir ZEKRI BEN YAHIA

FROM employees
WHERE first_name LIKE '%D%'
OR first_name LIKE '%S%'
OR first_name LIKE '%N%'
ORDER BY salary DESC;
16) SELECT first_name ||' '||last_name AS Full_Name, hire_date ,
commission_pct, email ||' - '||phone_number AS Contact_Details, salary
FROM employees
WHERE salary > 11000
OR phone_number LIKE '______3%'
ORDER BY first_name DESC;
17) SELECT job_id, COUNT(*), SUM(salary),
MAX(salary)-MIN(salary) AS salary_difference
FROM employees
GROUP BY job_id;
18) SELECT manager_id, COUNT(*)
FROM employees
GROUP BY manager_id;
19) SELECT DISTINCT department_id
FROM employees
GROUP BY department_id, manager_id
HAVING COUNT(employee_id) >=4;

You might also like