Sei sulla pagina 1di 2

1 -- Question 1 :

2 -- a :
3 select name
4 from country
5 where population > 60000000
6
7 -- b :
8 select name
9 from country
10 where population > 60000000
11 order by name asc
12
13 -- c :
14 select name , population
15 from country
16 order by population desc
17
18 -- d :
19 select name , area
20 from country
21 order by area
22 limit 10
23
24 -- e :
25 select name , area
26 from country
27 order by area
28 limit 10
29 offset 10
30
31
32 ----------------------------------------------
33 -- Question 2 :
34 CREATE TABLE encompasses (
35 -- liste de colonnes
36 country TEXT ,
37 continent VARCHAR ,
38 percentage REAL NOT NULL,
39 -- Contraintes :
40 Primary Key(country , continent),
41 Foreign key(country) references country(code),
42 Check (percentage between 0 and 100)
43
44 )
45
46 DROP TABLE encompasses
47
48 ALTER TABLE add column GPS TEXT DEFAULT '0,0'
49
50 -------------------------------------------------------
51 -- Question 3 :
52 -- a :
53 select distinct c.name
54 from country c
55 join encompasses e
56 on e.country = c.code
57 where e.percentage < 100
58
59 --b :
60 -- Avec jointure
61 select c.name , c.population / c.area as density
62 from country c
63 join encompasses e
64 on e.country = c.code
65 where e.continent like '_meri%'
66 AND density < 10
67 -- sans jointure : avec sous requete (imbriqué)
68 select name , population / area as density
69 from country
70 where code IN (select country
71 from encompasses
72 where continent like '_meri%'
73 )
74 AND density < 10
75 -- les pays non américain qui comptent moins de 10 habitants par km²
76 select name , population / area as density
77 from country
78 where code NOT IN (select country
79 from encompasses
80 where continent like '_meri%'
81 )
82 AND density < 10
83 -- c :
84 select e.continent , sum(c.population) as S
85 from country c
86 join encompasses e
87 on e.country = c.code
88 group by e.continent
89 having S > 1000000000
90
91 -- d :
92 select name
93 from country
94 where population/area > (select avg(population/area)
95 from country
96 )
97 -- Question 4 :
98 -- a :
99 select name , count(distinct country) as nb
100 from language
101 group by name
102 order by nb desc
103 limit 10
104
105 --b :
106 select c.name , L.name
107 from country c
108 join language L
109 on c.code = L.country
110 where L.name in (select name
111 from language
112 group by name
113 having count(*) = 6
114
115 )
116
117 -- c :
118
119
120
121
122
123
124
125
126
127

Potrebbero piacerti anche