Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. CREATE TABLE Pays
  2. (
  3. Ville varchar(15) PRIMARY KEY,
  4. Nompays varchar(20)
  5. );
  6.  
  7. CREATE TABLE Avion
  8. (
  9. NumAv number(4) PRIMARY KEY,
  10. ModAv varchar(20),
  11. CapAv number(4),
  12. VilleAv varchar(15),
  13. CONSTRAINT Avion_PAYS_VILLE_fk FOREIGN KEY (VilleAv) REFERENCES PAYS (VILLE)
  14. );
  15.  
  16. CREATE TABLE pilote
  17. (
  18. NumPil number(4) PRIMARY KEY,
  19. NomPil varchar(20),
  20. dateNaissPil date,
  21. villePil varchar(15),
  22. CONSTRAINT pilote_PAYS_VILLE_fk FOREIGN KEY (villePil) REFERENCES PAYS (VILLE)
  23. );
  24.  
  25. CREATE TABLE client
  26. (
  27. NumCl number(5) PRIMARY KEY,
  28. NomCl varchar(15),
  29. NumNomCl number(3),
  30. NomRueCl varchar(50),
  31. CodePosteCl number(5),
  32. VilleCl varchar(15),
  33. email varchar(50),
  34. CONSTRAINT client_PAYS_VILLE_fk FOREIGN KEY (VilleCl) REFERENCES PAYS (VILLE)
  35. );
  36.  
  37. CREATE TABLE VOL
  38. (
  39. NumVol varchar(5) PRIMARY KEY,
  40. VilleD varchar(15),
  41. VilleA varchar(15),
  42. DateD date,
  43. DateA date,
  44. NumPil number(4),
  45. NumAv number(4),
  46. CoutVol number(4),
  47. CONSTRAINT VOL_PAYS_VILLE_fk FOREIGN KEY (VilleD) REFERENCES PAYS (VILLE),
  48. CONSTRAINT VOL_PILOTE_NUMPIL_fk FOREIGN KEY (NumPil) REFERENCES PILOTE (NUMPIL),
  49. CONSTRAINT VOL_AVION_NUMAV_fk FOREIGN KEY (NumAv) REFERENCES AVION (NUMAV),
  50. CONSTRAINT VOL_PAYS_VILLE_fk_2 FOREIGN KEY (VilleA) REFERENCES PAYS (VILLE)
  51. );
  52.  
  53. CREATE TABLE classe
  54. (
  55. NumVol varchar(5),
  56. NomClasse varchar(15),
  57. CoeffPlace number(4,3),
  58. CoeffPrix number(2,1),
  59. CONSTRAINT classe_pk PRIMARY KEY (NumVol, NomClasse),
  60. CONSTRAINT classe_VOL_NUMVOL_fk FOREIGN KEY (NumVol) REFERENCES VOL (NUMVOL)
  61. );
  62.  
  63. CREATE TABLE reservation
  64. (
  65. NumCl number(5),
  66. NumVol varchar(5),
  67. NomClasse varchar(15),
  68. nbPlaces number(3),
  69. CONSTRAINT reservation_pk PRIMARY KEY (NumCl, NumVol, NomClasse),
  70. CONSTRAINT reservation_CLIENT_NUMCL_fk FOREIGN KEY (NumCl) REFERENCES CLIENT (NUMCL),
  71. CONSTRAINT reservation_VOL_NUMVOL_fk FOREIGN KEY (NumVol) REFERENCES VOL (NUMVOL)
  72. );
  73.  
  74. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Paris', 'France');
  75. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Bordeaux', 'France');
  76. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Grenoble', 'France');
  77. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Marseille', 'France');
  78. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Lyon', 'France');
  79. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Aix', 'France');
  80. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('La Ciotat', 'France');
  81. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Trets', 'France');
  82. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Amsterdam', 'Pays-Bas');
  83. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Madrid', 'Espagne');
  84. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Rome', 'Italie');
  85. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Milan', 'Italie');
  86. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Londres', 'Angleterre');
  87. INSERT INTO louppe7u.PAYS (VILLE, NOMPAYS) VALUES ('Lille', 'France');
  88.  
  89. Insert into Avion Values (1234,'AIRBUS A300',30,'Paris') ;
  90. Insert into Avion Values (1512,'AIRBUS A600',60,'Grenoble') ;
  91. Insert into Avion Values (7932,'BOEING 707',20,'Marseille') ;
  92. Insert into Avion Values (8121,'Cesna',4,'Marseille') ;
  93. Insert into Avion Values (9867, 'Cesna',4,'Paris') ;
  94. Insert into Avion Values (1259,'AIRBUS A300',30,'Lyon') ;
  95. Insert into Avion Values (7713,'BOEING 737',50,'Bordeaux') ;
  96. Insert into Avion Values (1599,'BOEING 737',50,'Lyon') ;
  97. Insert into Avion Values (3384,'AIRBUS A200',20,'Grenoble') ;
  98. Insert into Avion Values (6691, 'BOEING 747',60,'Paris') ;
  99.  
  100. Insert into Pilote Values (7802, 'DURAND','01/10/1950','Bordeaux') ;
  101. Insert into Pilote Values (6991, 'DAVIR','25/04/1954','Paris') ;
  102. Insert into Pilote Values (6789, 'DUPUIS','20/05/1970','Marseille') ;
  103. Insert into Pilote Values (4003, 'LAMBERT','12/11/1965','Grenoble') ;
  104. Insert into Pilote Values (5002, 'DURAND','14/08/1951','Paris') ;
  105. Insert into Pilote Values (8837, 'SMITH','23/09/1971','Bordeaux') ;
  106. Insert into Pilote Values (7654, 'ROBERT','11/02/1954','Marseille') ;
  107. Insert into Pilote Values (3947, 'SCHMIDT','03/01/1963','Paris') ;
  108. Insert into Pilote Values (3240, 'ALONSO','30/07/1968', 'Paris');
  109. Insert into Pilote Values (5407, 'DELTAN','08/05/1968','Lyon') ;
  110.  
  111.  
  112. Insert into Client Values (7003,'DUTIER',7,'Gambetta',13100,'Aix', 'alec.dutier@gmail.com');
  113. Insert into Client Values (9012,'RIBEIRA',34,'Mistral',13600,'La Ciotat', 'paul.ribiera@yahoo.fr');
  114. Insert into Client Values (8347,'VALOIS',62,'Mitterand',13600,'La Ciotat','clement.valois@hotmail.fr');
  115. Insert into Client Values (6692,'GARI',3,'Mirabeau',13530,'Trets','gino.gari@gmail.com');
  116. Insert into Client Values (7387,'CARRO',122,'Serpolet',13008,'Marseille','vivak.carro@yahoo.fr');
  117. Insert into Client Values (5407,'FAVER',15,'Hugo',13530,'Trets', 'david.faver@me.com');
  118. Insert into Client Values (7631,'BOSS',17,'Papere',13001,'Marseille', 'florian.boss@orange.fr');
  119. Insert into Client Values (2781,'MARI',9,'Montigny',13100,'Aix', 'stephane.mari@free.fr');
  120. Insert into Client Values (1107,'GIROLLE',53,'St Anne',13100,'Aix','anne.girolle@gmail.com');
  121. Insert into Client Values (1752,'RALLINO',84,'Italie',13002,'Marseille',null );
  122.  
  123. Insert into Vol Values ('V12A1','Marseille','Paris',to_date('08/01/2019-15:17','DD/MM/YYYY-HH24:MI'),to_date('08/01/2019-16:35','DD/MM/YYYY-HH24:MI'),7654,7713, 35);
  124. Insert into Vol Values ('V9000','Marseille','Lyon', to_date('08/01/2019-20:30','DD/MM/YYYY-HH24:MI'),to_date('08/01/2019-21:10','DD/MM/YYYY-HH24:MI'), 5407,6691, 40);
  125. Insert into Vol Values ('V7B90','Marseille','Bordeaux',to_date('17/02/2019-07:10','DD/MM/YYYY-HH24:MI'), to_date('17/02/2019-08:25','DD/MM/YYYY-HH24:MI'),8837,8121,32);
  126. Insert into Vol Values ('V66AA','Marseille','Grenoble',to_date('17/02/2019-07:05','DD/MM/YYYY-HH24:MI'),to_date('17/02/2019-08:15','DD/MM/YYYY-HH24:MI'),5002,1512,50);
  127. Insert into Vol Values ('V0702','Paris', 'Lyon',to_date('30/11/2019-15:00','DD/MM/YYYY-HH24:MI'),to_date('30/11/2019-16:05','DD/MM/YYYY-HH24:MI'),4003,6691,43);
  128. Insert into Vol Values ('V8D90','Paris','Marseille',to_date('18/02/2019-16:10','DD/MM/YYYY-HH24:MI'),to_date('18/02/2019-17:40','DD/MM/YYYY-HH24:MI'),5002,1234,35);
  129. Insert into Vol Values ('V8E90','Paris','Bordeaux',to_date('04/02/2019-19:30','DD/MM/YYYY-HH24:MI'),to_date('04/02/2019-20:35','DD/MM/YYYY-HH24:MI'),7654,7713,38);
  130. Insert into Vol Values ('V8000', 'Lyon','Paris',to_date('14/12/2019-18:10','DD/MM/YYYY-HH24:MI'),to_date('14/12/2019-19:20','DD/MM/YYYY-HH24:MI'),3947,3384,39);
  131. Insert into Vol Values ('V74FG','Bordeaux','Paris',to_date('05/02/2019-12:20','DD/MM/YYYY-HH24:MI'),to_date('05/02/2019-13:30','DD/MM/YYYY-HH24:MI'),3240,1599,41);
  132. Insert into Vol Values ('V327B', 'Lyon','Marseille',to_date('06/02/2019-20:00','DD/MM/YYYY-HH24:MI'),to_date('06/02/2019-21:30','DD/MM/YYYY-HH24:MI'),7802,9867,70);
  133. Insert into Vol Values('V9200', 'Lyon', 'Amsterdam', to_date('02/06/2019-20:00','DD/MM/YYYY-HH24:MI'), to_date('02/06/2019-21:50','DD/MM/YYYY-HH24:MI'), 6991, 1234, 74);
  134. Insert into Vol Values('V9201', 'Lyon', 'Madrid', to_date('02/05/2019-08:00','DD/MM/YYYY-HH24:MI'), to_date('02/05/2019-09:50','DD/MM/YYYY-HH24:MI'), 6991, 1512, 63);
  135. Insert into Vol Values('V9202', 'Lyon', 'Rome', to_date('02/02/2019 10:00','DD/MM/YYYY-HH24:MI'), to_date('02/02/2019 10:50','DD/MM/YYYY-HH24:MI'), 6991, 7713, 42);
  136. Insert into Vol Values('V9203', 'Paris', 'Bordeaux', to_date('02/04/2019-13:00','DD/MM/YYYY-HH24:MI'), to_date('02/04/2019-14:50','DD/MM/YYYY-HH24:MI'), 6991, 8121, 84);
  137. Insert into Vol Values('V9204', 'Lille', 'Marseille',to_date( '02/06/2019-15:00','DD/MM/YYYY-HH24:MI'), to_date('02/06/2019-16:50','DD/MM/YYYY-HH24:MI'), 6991, 3384, 95);
  138. Insert into Vol Values('V9205', 'Lyon', 'Milan', to_date('02/05/2019-18:00','DD/MM/YYYY-HH24:MI'), to_date('02/05/2019-19:50','DD/MM/YYYY-HH24:MI'), 6991, 6691, 74);
  139. Insert into Vol Values('V9206', 'Lyon', 'Londres', to_date('02/01/2019-17:00','DD/MM/YYYY-HH24:MI'), to_date('02/01/2019-18:50','DD/MM/YYYY-HH24:MI'), 6991, 7932, 84);
  140.  
  141.  
  142. Insert into Reservation Values(7003,'V9000','AFF',3);
  143. Insert into Reservation Values(1752,'V9000','ECO',4);
  144. Insert into Reservation Values(1107,'V8000','TOUR',2);
  145. Insert into Reservation Values(1107,'V8D90','TOUR',2);
  146. Insert into Reservation Values(2781,'V327B','AFF',1);
  147. Insert into Reservation Values(6692,'V8E90','ECO',3);
  148. Insert into Reservation Values(6692,'V327B','TOUR',2);
  149. Insert into Reservation Values(9012,'V74FG','ECO',1);
  150. Insert into Reservation Values(5407,'V9000','AFF',2);
  151. Insert into Reservation Values(5407,'V0702','TOUR',4);
  152.  
  153.  
  154. Insert into classe values ('V9200', 'ECO',0.2,1.0);
  155. Insert into classe values ('V9201', 'ECO',0.2,1.0);
  156. Insert into classe values ('V9202', 'ECO',0.2,1.0);
  157. Insert into classe values ('V9203', 'ECO',0.2,1.0);
  158. Insert into classe values ('V9204', 'ECO',0.2,1.0);
  159. Insert into classe values ('V9205', 'ECO',0.2,1.0);
  160. Insert into classe values ('V9206', 'ECO',0.2,1.0);
  161. Insert into classe values ('V9000', 'AFF', 0.4,2) ;
  162. Insert into classe values ('V9000', 'TOUR', 0.4,1.5) ;
  163. Insert into classe values ('V9000', 'ECO', 0.2,1) ;
  164. insert into classe values ('V0702', 'ECO', 0.2, 1);
  165. insert into classe values ('V12A1', 'ECO', 0.2, 1);
  166. insert into classe values ('V66AA', 'ECO', 0.2, 1);
  167. insert into classe values ('V74FG', 'ECO', 0.2, 1);
  168. insert into classe values ('V7B90', 'ECO', 0.2, 1);
  169. insert into classe values ('V8000', 'ECO', 0.2, 1);
  170. insert into classe values ('V8D90', 'ECO', 0.2, 1);
  171. insert into classe values ('V8E90', 'ECO', 0.2, 1);
  172. insert into classe values ('V327B', 'ECO', 0.2, 1);
  173. insert into classe values ('V327B', 'AFF', 0.2, 2);
  174. insert into classe values ('V8000', 'TOUR', 0.6, 1.5);
  175. insert into classe values ('V8D90', 'TOUR', 0.6, 1.5);
  176. insert into classe values ('V327B', 'TOUR', 0.6, 1.5);
  177. insert into classe values ('V0702', 'TOUR', 0.6, 1.5);
  178.  
  179. --question 5
  180. select avg(CoutVol) from VOL
  181. inner join pays on VOL.VilleD = Pays.Ville
  182. group by Ville;
  183.  
  184. --question 6
  185. select count(DISTINCT VilleA, VilleD) from VOL
  186.  
  187. ;
  188. --question 7
  189. select sum(nbPlaces) from reservation
  190. where NumVol ='V9000';
  191.  
  192. --question 8
  193. select count(*) as nombreservation, client.NomCl from reservation
  194. inner join client on reservation.NumCl = client.NumCl
  195. group by client.NomCl;
  196.  
  197. --question 9 ENLEVER LA COLONNE NBRES
  198. select count(*) as nbreservation, client.NomCl, client.NumCl from reservation
  199. inner join client on reservation.NumCl = client.NumCl
  200. group by client.NomCl, client.NumCl
  201. having count(*)>1;
  202.  
  203. --question 10
  204. select NomPil, NumPil from pilote
  205. where NumPil not in (select distinct NumPil from VOL);
  206.  
  207. --question 11
  208. select sum((DateA - DateD)*24) as tempsvol, pilote.NumPil from VOL
  209. inner join pilote on VOL.NumPil = pilote.NumPil
  210. group by pilote.NumPil;
  211.  
  212. --question 12 TO DO
  213. select max(tempsvol)from (
  214. select sum((DateA - DateD)*24) as tempsvol, pilote.NumPil from VOL
  215. inner join pilote on VOL.NumPil = pilote.NumPil
  216. group by pilote.NumPil
  217. )
  218. ;
  219.  
  220.  
  221. --question 13
  222. select count(distinct avion.ModAv) as nbavionpilotes, pilote.NomPil from Avion
  223. inner join VOL on Avion.NumAv = VOL.NumAv
  224. inner join pilote on VOL.NumPil = pilote.NumPil
  225. group by pilote.NomPil
  226. having count(distinct avion.ModAv) = (select count(distinct avion.ModAv) as nbavionpilotes from Avion)
  227. ;
  228.  
  229. --question 14
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement