TP2
TP2
nomproj Varchar(10),
/* table creee */
(1,'gamma',320000);
(2,'papyrus',250000);
(3,'rodin',280000);
(4,'alpha',200000);
commit;
/* validation effectuee */
nomdept Varchar(20),
lieu Varchar(20));
/* table creee */
(10,'finances','paris');
(20,'recherche','grenoble');
insert into Dept values
(30,'ventes','lyon');
(40,'fabrication','lille');
commit;
/* validation effectuee */
nomemp Varchar(20),
poste Varchar(20),
supr number(4),
datemb date,
sal number(4),
comm number(4),
/* table creee */
(7839,'leroy','president',Null,'17/11/2009',7250,Null,1,10);
(7566,'mercier','directeur',7839,'02/04/2001',5950,Null,2,20);
insert into Emp values
(7698,'noiret','directeur',7839,'01/05/2001',5700,Null,4,30);
(7782,'lesage','directeur',7839,'09/06/2001',4900,Null,1,10);
(7788,'dubois','ingenieur',7566,'14/04/2005',6000,Null,2,20);
(7902,'chatel','ingenieur',7566,'03/12/2001',6000,Null,2,20);
(7369,'leclerc','commercial',7902,'17/12/2000',1800,null,2,20);
(7499,'biraud','commercial',7698,'20/02/2001',3200,600,3,30);
(7521,'berger','commercial',7698,'22/02/2001',2750,1000,4,30);
(7654,'martin','commercial',7698,'28/12/2001',2750,2800,3,30);
(7844,'benain','commercial',7698,'08/09/2001',3000,Null,3,30);
(7876,'clement','secretaire',7788,'18/05/2005',2200,Null,2,20);
(7900,'fremont','secretaire',7698,'03/12/2001',1900,Null,3,30);
(7934,'villard','secretaire',7782,'23/01/2002',2600,Null,3,30);
commit;
/* Validation effectuée */
/* QUESTIONS */
/* Q1 */
select distinct poste from Emp where sal >= 2500 order by poste desc;
/* Q2 */
/*Q3 */
select noemp from Emp where noproj in(select noproj from Projet where nomproj = 'alpha');
/* Q4 */
select noemp from Emp where nodept in(select nodept from Dept where nomdept = 'recherche');
/* Q5 */
select noemp from Emp where nodept in(select nodept from Dept where nomdept = 'fabrication')
intersect select noemp from Emp where noproj in(select noproj from Projet where nomproj =
'alpha');
/* Q6 */
select nomemp, poste, sal from Emp where nodept in(select nodept from Dept where nomdept =
'ventes');
/* Q7 */
select nomemp, poste from Emp where poste = (select poste from Emp where nomemp = 'biraud');
/* Q8 */
/* forme procedurale */
from Emp
intersect
/* forme procedurale */
select nomemp
from Emp
and sal > (select sal from Emp where poste = 'directeur' and nodept in(select nodept from Dept
where nomdept='ventes'));
/* forme relationnelle */
select e1.nomemp
/* Q9 */
from Emp
Group by nodept;
/* Q10 */
select poste,round(avg(sal))
from Emp
group by poste
/* Q11 */
from Emp
Group by poste;
/* Q12 */
select nomemp,poste,sal
from Emp
/* attention pour la comparaison: on compare soit 2 valeurs soit avec une sous-requete qui retourne
une valeur */
/* Q13 */
select poste
from Emp
group by poste
/* PARTIE 2 */
/* Q1 */
(50,'achats','toulouse');
commit;
(7986,'richard','directeur',7839,'01/09/2006',6500,1250,1,50);
commit;
/* Q2 */
/* Q3 */
delete Emp
or nomdept = 'fabrication';
/* FIN