fork download
  1. create table mountains(
  2. id int auto_increment primary key,
  3. name varchar (50),
  4. height int,
  5. country varchar(30)
  6. );
  7. create table mountainers(
  8. id int auto_increment primary key,
  9. nationality varchar (50),
  10. experience int
  11. );
  12. alter table mountaineers add column name varchar(30);
  13. create table sherpas(
  14. id int auto_increment primary key,
  15. name varchar (50),
  16. nationality varchar(30)
  17. );
  18.  
  19. create table teams(
  20. id int auto_increment primary key,
  21. name varchar (50),
  22. country varchar(30)
  23. );
  24. create table expeditions(
  25. id int auto_increment primary key,
  26. mountain_id int,
  27. team_id int,
  28. year int,
  29. foreign key (mountain_id) references mountains(id),
  30. foreign key (team_id) references teams(id)
  31. );
  32.  
  33. alter table mountainers rename to mountaineers;
  34. create table exploits(
  35. id int auto_increment primary key,
  36. mountaineer_id int,
  37. expedition_id int,
  38. success boolean,
  39. foreign key (mountaineer_id) references mountaineers(id),
  40. foreign key (expedition_id) references expeditions(id)
  41. );
  42. create table participation(
  43. mountaineer_id int,
  44. expedition_id int,
  45. role varchar(30),
  46. foreign key (mountaineer_id) references mountaineers(id),
  47. foreign key (expedition_id) references expeditions(id)
  48. );
  49.  
  50.  
  51. INSERT INTO Mountains VALUES
  52. (1,'Everest',8848,'Nepal'),
  53. (2,'K2',8611,'Pakistan'),
  54. (3,'Kangchenjunga',8586,'Nepal/India'),
  55. (4,'Lhotse',8516,'Nepal'),
  56. (5,'Makalu',8485,'Nepal'),
  57. (6,'ChoOyu',8188,'Nepal'),
  58. (7,'Dhaulagiri',8167,'Nepal'),
  59. (8,'Manaslu',8163,'Nepal'),
  60. (9,'NangaParbat',8126,'Pakistan'),
  61. (10,'Annapurna',8091,'Nepal');
  62.  
  63. INSERT INTO Mountaineers(id, name,nationality, experience) VALUES
  64. (1,'Messner','Italy',50),
  65. (2,'Hillary','NZ',30),
  66. (3,'Tenzing','Nepal',25),
  67. (4,'Kukuczka','Poland',40),
  68. (5,'Moro','Italy',20),
  69. (6,'Steck','Swiss',25),
  70. (7,'Purja','Nepal',15),
  71. (8,'Bonington','UK',35),
  72. (9,'Urubko','Kazakh',30),
  73. (10,'Hinkes','UK',28);
  74.  
  75. INSERT INTO Sherpas VALUES
  76. (1,'Kami Rita','Nepal'),
  77. (2,'Apa','Nepal'),
  78. (3,'Phurba','Nepal'),
  79. (4,'Ang Rita','Nepal'),
  80. (5,'Pasang','Nepal'),
  81. (6,'Lakpa','Nepal'),
  82. (7,'Mingma','Nepal'),
  83. (8,'Dawa','Nepal'),
  84. (9,'Pemba','Nepal'),
  85. (10,'Dorje','Nepal');
  86.  
  87.  
  88.  
  89. INSERT INTO Teams VALUES
  90. (1,'Italian Team','Italy'),
  91. (2,'British Team','UK'),
  92. (3,'Nepal Team','Nepal'),
  93. (4,'Polish Team', 'Poland'),
  94. (5,'Swiss Team','Swiss'),
  95. (6,'French Team','France'),
  96. (7,'German Team','Germany'),
  97. (8,'Spanish Team','Spain'),
  98. (9,'US Team','USA'),
  99. (10,'Japan Team','Japan');
  100.  
  101. INSERT INTO Expeditions VALUES
  102. (1,1,3,1953),
  103. (2,2,4,1986),
  104. (3,3,4,1980),
  105. (4,4,1,1970),
  106. (5,5,2,1985),
  107. (6,6,5,2000),
  108. (7,7,6,1990),
  109. (8,8,7,1995),
  110. (9,9,8,2005),
  111. (10,10,9,2010);
  112.  
  113.  
  114. INSERT INTO Exploits VALUES
  115. (1,2,1,TRUE),
  116. (2,3,1,TRUE),
  117. (3,1,2,TRUE),
  118. (4,4,3,TRUE),
  119. (5,5,5, TRUE ), (6,6,6, TRUE ), (7,7,9, TRUE ), (8,8,4, TRUE ), (9,9,2, TRUE ), (10,10,10, TRUE );
  120.  
  121. INSERT INTO Participation VALUES
  122. (1,2,'Leader'),
  123. (2,1,'Leader'),
  124. (3,1,'Guide'),
  125. (4,3,'Leader'),
  126. (5,5,'Climber'),
  127. (6,6,'Climber'),
  128. (7,9,'Leader'),
  129. (8,4,'Climber'),
  130. (9,2,'Climber'),
  131. (10,10,'Leader');
  132.  
  133. alter table mountaineers add column age int;
  134. alter table teams rename to ClimbingTeams;
  135. alter table sherpas add column experience int;
  136.  
  137. -- question1
  138.  
  139. select * from mountains;
  140.  
  141. -- question2
  142.  
  143. select * from mountaineers where experience>20;
  144.  
  145. -- question 3
  146. select * from mountains order by height desc;
  147.  
  148. -- question 4
  149.  
  150. select * from Climbingteams order by country;
  151.  
  152.  
  153. -- question 5
  154.  
  155. select * from expeditions where year>1990;
  156.  
  157. -- question 6
  158. select * from mountaineers where nationality='Italy';
  159.  
  160. -- question 7
  161. select count(*) as "nombre de sommets" from mountains;
  162.  
  163. -- question 8
  164.  
  165. select * from sherpas;
  166.  
  167. -- question 9
  168. select * from ClimbingTeams where name like '%Team%';
  169.  
  170. -- question 10
  171.  
  172. select * from expeditions where mountain_id=1;
  173.  
  174.  
  175. -- question 11
  176.  
  177. update mountaineers set experience=40 where id=2;
  178.  
  179. -- question 12
  180.  
  181. delete from expedition where id=1;
  182.  
  183. -- pour forcer la suppression
  184. alter table expeditions drop constraint `expeditions_ibfk_1`;
  185. alter table expeditions drop constraint `expeditions_ibfk_2`;
  186.  
  187.  
  188.  
  189.  
  190. -- question 13
  191.  
  192. insert into mountains (name, height,country) values('Toubkal',4196,'MOROCCO');
  193. select * from mountains;
  194.  
  195. -- question 14
  196.  
  197. update climbingteams set country='Maghrib' where id=1;
  198.  
  199. -- question 15
  200.  
  201. delete from mountaineers where id=10;
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
Success #stdin #stdout #stderr 0.01s 5308KB
stdin
Standard input is empty
stdout
1|Everest|8848|Nepal
2|K2|8611|Pakistan
3|Kangchenjunga|8586|Nepal/India
4|Lhotse|8516|Nepal
5|Makalu|8485|Nepal
6|ChoOyu|8188|Nepal
7|Dhaulagiri|8167|Nepal
8|Manaslu|8163|Nepal
9|NangaParbat|8126|Pakistan
10|Annapurna|8091|Nepal
1|Everest|8848|Nepal
2|K2|8611|Pakistan
3|Kangchenjunga|8586|Nepal/India
4|Lhotse|8516|Nepal
5|Makalu|8485|Nepal
6|ChoOyu|8188|Nepal
7|Dhaulagiri|8167|Nepal
8|Manaslu|8163|Nepal
9|NangaParbat|8126|Pakistan
10|Annapurna|8091|Nepal
6|French Team|France
7|German Team|Germany
1|Italian Team|Italy
10|Japan Team|Japan
3|Nepal Team|Nepal
4|Polish Team|Poland
8|Spanish Team|Spain
5|Swiss Team|Swiss
2|British Team|UK
9|US Team|USA
6|6|5|2000
8|8|7|1995
9|9|8|2005
10|10|9|2010
10
1|Kami Rita|Nepal|
2|Apa|Nepal|
3|Phurba|Nepal|
4|Ang Rita|Nepal|
5|Pasang|Nepal|
6|Lakpa|Nepal|
7|Mingma|Nepal|
8|Dawa|Nepal|
9|Pemba|Nepal|
10|Dorje|Nepal|
1|Italian Team|Italy
2|British Team|UK
3|Nepal Team|Nepal
4|Polish Team|Poland
5|Swiss Team|Swiss
6|French Team|France
7|German Team|Germany
8|Spanish Team|Spain
9|US Team|USA
10|Japan Team|Japan
1|1|3|1953
1|Everest|8848|Nepal
2|K2|8611|Pakistan
3|Kangchenjunga|8586|Nepal/India
4|Lhotse|8516|Nepal
5|Makalu|8485|Nepal
6|ChoOyu|8188|Nepal
7|Dhaulagiri|8167|Nepal
8|Manaslu|8163|Nepal
9|NangaParbat|8126|Pakistan
10|Annapurna|8091|Nepal
|Toubkal|4196|MOROCCO
stderr
Error: near line 12: no such table: mountaineers
Error: near line 63: table Mountaineers has no column named name
Error: near line 181: no such table: expedition
Error: near line 184: near "drop": syntax error
Error: near line 185: near "drop": syntax error