Corrigé TP2_SQL(partie1)
Corrigé TP2_SQL(partie1)
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
//Q4
select Nom_Emp,Fonction_Emp,Salaire_Emp
from EMPLOYE
//Q5
select Nom_Emp,Fonction_Emp,Salaire_Emp
from EMPLOYE
//Q6
select Nom_Emp,Fonction_Emp
from EMPLOYE
//Q7
select Nom_Emp,Fonction_Emp,Num_Dep
EPI Sousse
Abir ZEKRI BEN YAHIA
from EMPLOYE
//Q8
select Nom_Emp,Fonction_Emp,Salaire_Emp
from EMPLOYE
//Q9
select Nom_Emp,Fonction_Emp,Num_Dep
from EMPLOYE
//Q10
select *
from EMPLOYE
//Q11
select *
from EMPLOYE
//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
select *
from EMPLOYE
//Q15
from EMPLOYE
//Q16
from EMPLOYE
where Fonction_Emp='ouvrier'
//Q17
from EMPLOYE
//Q18
from EMPLOYE
where Num_Dep=10
//Q19
from EMPLOYE
where Num_Dep=10
//Q20
from EMPLOYE
group by Num_Dep
//Q21
from EMPLOYE
where Fonction_Emp not in ('directeur','president')
EPI Sousse
Abir ZEKRI BEN YAHIA
group by Num_Dep
//Q22
from EMPLOYE
group by Num_Dep,Fonction_Emp
//Q23
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
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)
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;