RAPPORT DE TP 4 BASE DE DONNÉES DAO SIDIKI GÉNIE LOGICIEL G3
1) Création de la table client et de la table de location.
Create Table Client(NC Smallint Primary Key, Nom Varchar(15), Prenom Varchar(15),
Adresse Varchar(50) );
Create Table Location(NC Smallint, NCH Smallint, DL Date, PL Smallint Unsigned, Primary
Key(NC,NCH,DL), Foreign Key(NC) references Client(NC), Foreign Key(NCH) references
Chambre(NC) );
2) Insertions des clients sur la table Client.
Insert into Client values(3,”Sidiki”,”Dao”,”Rabat-Morocco”);
Insert into Client values(4,”Soumaila”,”Dabanguibe”,”Rabat-Morocco”);
Insert into Client values(5,”Noura”,”Larwanou”,”Rabat-Morocco”);
Insert into Client values(6,”Sidiki”,”Issa”,”Salé-Morocco”);
3) Insertions pour chaque client des locations.
Insert Into Location Values (3,53,'2015-03-31',30) , (4,69,'2014-08-08',25) ,
(5,31,'2015-01-01',9), (6,30,’2015-01-01’,9);
4) Afficher tous les clients.
Select * from client;
5) Afficher les clients ayant loué la chambre N° 2.
Select * from Client cl , Location l Where cl.NC = l.NC and NCH = 2;
6) Afficher les clients ayant loué une chambre dont les frais de location dépassent 250.
Select cl.Nom, Prenom from Client cl , Location l , CategorieChambre cc , Chambre c Where
cl.NC = l.NC and c.NTC = cc.NTC and c.NC = l.NCH and FL > 250;
7) Afficher pour chaque location ses frais FL*PL.
Select DL, PL, FL*PL from Location l , CategorieChambre cc , Chambre c Where c.NTC = cc.NTC
and l.NCH = c.NC;
8) Afficher pour chaque location, le nom et le prénom du client, le nom du type de chambre louée, la
période de location, les frais de location par jour ainsi que les frais globaux de cette location FL*PL.
Select cl.Nom, Prenom, cc.Nom, PL, FL, FL*PL from Client cl, CategorieChambre cc, Chambre c,
Location l Where cl.NC = l.NC and c.NTC = cc.NTC and c.NC = l.NCH;
9) Afficher les chambres louées avant la date ‘10-1-2022”.
Select NCH from Location where DL < ’2022-01-10’;
10) Afficher les chambres louées pour une période entre 2 et 5 nuits.
Select NCH from Location where PL between 2 and 5;
11) Afficher pour chaque client le nombre de locations effectuées.
Select C.NC, count(*) from Location L JOIN Client C ON C.NC=L.NC group by C.NC;
12) Afficher pour chaque client le nombre de chambres louées.
Select C.NC, count(distinct cc.NC) from Location L JOIN Client C ON C.NC=L.NC JOIN Chambre
cc ON cc.NC=L.NCH group by C.NC;
13) Afficher pour chaque Chambre le nombre de clients l’ayant louée.
Select cc.NC, count(distinct C.NC) from Location L JOIN Client C ON C.NC=L.NC JOIN Chambre
cc ON cc.NC=L.NCH group by cc.NC;
14) Idem que 11 mais uniquement pour des périodes entre 3 et 7 nuits.
Select C.NC, count(*) from Location L JOIN Client C ON C.NC=L.NC where PL between 3 and 7
group by C.NC;
15) Idem que 13 mais uniquement pour des chambres dont les FL ne dépassent pas 150.
Select cc.NC, count(distinct C.NC) from Location L JOIN Client C ON C.NC=L.NC JOIN Chambre
cc ON cc.NC=L.NCH JOIN CategorieChambre ct on ct.NTC=cc.NTC where FL <= 150 group by
cc.NC;