-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEconomic Growth and Public Transport in the EU.sqbpro
304 lines (250 loc) · 5.58 KB
/
Economic Growth and Public Transport in the EU.sqbpro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
--- datasources: eurostat, world bank org
--- urls: https://ec.europa.eu/eurostat/en/ https://databank.worldbank.org/indicator/NY.GDP.MKTP.KD.ZG/1ff4a498/Popular-Indicators#
/*
DESCRIPTION: calculating rail density per 100km squared of land area as of 2021 in descending order
*/
CREATE TABLE RailDensity
AS
SELECT
L.CountryName,
Round(R.RailLines/(L.LandAreaKmSqr/100),1) AS 'Rail Density Per 100km Squared'
FROM
LandArea L
INNER JOIN
Rail R
ON
L.CountryName = R.CountryName AND L.Year = R.Year
WHERE
R.Year = 2021
AND
R.RailLines IS NOT NULL
ORDER BY
"Rail Density Per 100km Squared" DESC
---
/*
DESCRIPTION: GDP growth rate by country
*/
CREATE TABLE GDPGrowth
AS
WITH
GDP_CTE
AS (
SELECT
CountryName,
Year,
GDP,
CAST (LAG(GDP) OVER (PARTITION BY CountryName ORDER BY Year) AS REAL) AS PreviousYearGDP
FROM
T_GDP
)
SELECT
CountryName,
Year,
CAST (round(((GDP_CTE.GDP - PreviousYearGDP)/PreviousYearGDP)*100,2) AS REAL) AS GDPGrowthRate
FROM
GDP_CTE
WHERE
PreviousYearGDP IS NOT NULL
ORDER BY
"Year" DESC
---
/*
DESCRIPTION: Aggregate GDP Growth Rate Across EU
*/
CREATE TABLE AnnualGDPGrowth
AS
WITH
GDP_CTE
AS (
SELECT
Year,
sum(GDP) GDP,
LAG(sum(GDP)) OVER (PARTITION BY CountryName ORDER BY Year) AS PreviousYearGDP
FROM
T_GDP
GROUP BY
Year
)
SELECT
Year,
round(avg(((GDP_CTE.GDP - PreviousYearGDP)/PreviousYearGDP)*100),2) AS GDPGrowthRate
FROM
GDP_CTE
WHERE
PreviousYearGDP IS NOT NULL
GROUP BY
"Year"
ORDER BY
"YEAR"
---
/*
DESCRIPTION: rail per 10,000 people for each country as of 2021 (excluding Estonia due to lack of rail data)
*/
CREATE TABLE RailPer10000
AS
SELECT
Rail.CountryName,
round(RailLines/(CAST (TotalPopulation AS REAL)/10000),2) AS "Rail Per 1000 People"
FROM
Rail
JOIN
Population
ON
Population.CountryName = Rail.CountryName AND Population.Year = Rail.Year
WHERE
Population.Year = 2021 AND RailLines IS NOT NULL
ORDER BY
"Rail Per 1000 People" DESC
---
/*
DESCRIPTION: change in rail lines from 1995 to 2021 by CountryCode (excluding estonia due to lack of data)
*/
CREATE TABLE RailGrowth
AS
WITH Rail_CTE AS
(SELECT
CountryName,
Year,
CAST (RailLines AS REAL),
(CAST (RailLines AS REAL) - lag(CAST (RailLines AS REAL)) OVER (PARTITION BY CountryName ORDER BY Year)) AS "Change",
(CAST (RailLines AS REAL) - lag(CAST (RailLines AS REAL)) OVER (PARTITION BY CountryName ORDER BY Year))/lag(CAST (RailLines AS REAL)) OVER (PARTITION BY CountryName ORDER BY Year)*100 AS PercentageChange
FROM
Rail
WHERE
Year = 2021 OR Year = 1995
)
SELECT
CountryName,
Round(Change,3) AS "Change in km of rail from 1995 to 2021",
Round(PercentageChange,3) AS "Percentage change in km of rail from 1995 to 2021"
FROM
Rail_CTE
WHERE
Change IS NOT NULL
ORDER BY
PercentageChange DESC
---
/*
DESCRIPTION: annual GDP Per capita growth rate by country
*/
CREATE TABLE PerCapitaGDP AS
WITH
GDP_CTE
AS (
SELECT
G.CountryName,
G.Year,
GDP,
TotalPopulation,
GDP/TotalPopulation AS PerCapitaGDP,
CAST (LAG(GDP/TotalPopulation) OVER (PARTITION BY G.CountryName ORDER BY G.Year) AS REAL) AS LagPerCap
FROM
T_GDP G
JOIN
Population P
ON
G.CountryName = P.CountryName AND G.Year = P.Year
)
SELECT
CountryName,
Year,
round("PerCapitaGDP",2) AS 'Real GDP Per Capita',
CAST (round(((GDP_CTE.PerCapitaGDP - LagPerCap)/LagPerCap)*100,2) AS REAL) AS 'GDP Per Capita Growth'
FROM
GDP_CTE
WHERE
LagPerCap IS NOT NULL
ORDER BY
CountryName
---
WITH NewBuses_CTE AS
(
SELECT
N.CountryName CountryName,
N.Year Year,
lag((N.BusQuantity/(P.TotalPopulation/1000))) OVER (PARTITION BY N.CountryName ORDER BY N.Year) AS BusLag,
N.BusQuantity/(P.TotalPopulation/1000) AS BusPer1000
FROM
NewBuses N
JOIN
Population P
ON
N.CountryName = P.CountryName AND N.Year = p.Year
)
SELECT
CountryName,
Year,
round(BusPer1000, 2) AS "Buses Per Capita",
round(((BusPer1000 - BusLag)/BusLag)*100,2) AS "Change in Buses per Capita"
FROM
NewBuses_CTE
---
/*
DESCRIPTION: number of buses per 1000 people for each EU country, as of 2021
*/
CREATE TABLE Bus2021 AS
WITH NewBuses_CTE AS
(
SELECT
N.CountryName CountryName,
N.Year Year,
lag((N.BusQuantity/(P.TotalPopulation/1000))) OVER (PARTITION BY N.CountryName ORDER BY N.Year) AS BusLag,
N.BusQuantity/(P.TotalPopulation/1000) AS BusPer1000
FROM
NewBuses N
JOIN
Population P
ON
N.CountryName = P.CountryName AND N.Year = p.Year
)
SELECT
CountryName,
Year,
round(BusPer1000, 2) AS "Buses Per Capita"
FROM
NewBuses_CTE
WHERE
Year = 2021
---
/*
DESCRIPTION: Percentage change in the number of buses per 1000 people between 1996 and 2021 (exluding luxembourg due to lack of data)
*/
CREATE TABLE BusGrowth AS
WITH Bus_CTE AS
(
SELECT
N.CountryName Country,
N.Year Year,
CAST(BusQuantity AS REAL) AS '2021Bus',
CAST(lag(BusQuantity) OVER (PARTITION BY N.CountryName ORDER BY N.Year) AS REAL) AS '1995Bus'
FROM
NewBuses N
JOIN
Population P
ON
N.CountryName = P.CountryName AND N.Year = p.Year
WHERE
N.Year = 1995 OR N.Year = 2021
)
SELECT
Country,
round((("2021Bus"-"1995Bus")/"1995Bus")*100,2) AS 'Change in Buses Per Capita'
FROM
Bus_CTE
WHERE
"Change in Buses Per Capita" IS NOT NULL
---
/*
DESCRIPTION: Ranking countries by average growth in transportation provision from 1995 to 2021
*/
CREATE TABLE GrowthRank AS
SELECT
B.Country,
RANK() OVER (ORDER BY ("Change in Buses Per Capita"+"Percentage change in km of rail from 1995 to 2021")/2 DESC) Rank,
("Change in Buses Per Capita"+"Percentage change in km of rail from 1995 to 2021")/2 AS 'Average Transport Growth'
FROM
BusGrowth B
JOIN
RailGrowth R
ON
B.Country = R.CountryName