Skip to content

Commit 2c5ed6b

Browse files
Finished Question 3
I didn't like what the question was asking and took a sum of each continents GDP per capita instead of any other metric for the sake of time. However this metric is a bit strange but this data needs more information in order to properly answer the question, EG, population of each country in the year 2012
1 parent 8c63e79 commit 2c5ed6b

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

alexander_connelly_code_challenge.txt

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,63 @@ AUS Australia OC Oceania 2004 30464.00376
144144

145145
/*Using this view as my dataset to refer to, I'll answer the GDP question with this query:*/
146146

147+
use braintree;
147148

149+
CREATE TABLE gdp_growth_rank (
150+
SELECT
151+
t1.continent_name,
152+
t1.country_code,
153+
t1.country_name,
154+
CONCAT(ROUND(((t2.gdp_2012 - t1.gdp_2011) / t1.gdp_2011) * 100,
155+
2),
156+
'%') AS growth_percent
157+
158+
,RANK() OVER (PARTITION BY t1.continent_name order by ((t2.gdp_2012 - t1.gdp_2011) / t1.gdp_2011) desc) as drank
159+
FROM
160+
(SELECT
161+
continent_name,
162+
country_code,
163+
country_name,
164+
gdp_per_capita AS 'gdp_2011'
165+
FROM
166+
gdp_join
167+
WHERE
168+
year = 2011) t1
169+
INNER JOIN
170+
(SELECT DISTINCT
171+
country_code, gdp_per_capita AS 'gdp_2012'
172+
FROM
173+
gdp_join
174+
WHERE
175+
year = 2012) t2 ON t1.country_code = t2.country_code);
176+
177+
/*after saving the results of our select statement above, query the resulting table to get ranks 10-12 for each continent*/
178+
179+
SELECT * FROM braintree.gdp_growth_rank
180+
181+
where drank > 9 and drank < 13;
182+
183+
/* yields these results!*/
184+
185+
rank continent_name country_code country_name growth_percent
186+
10 Africa RWA Rwanda 8.73%
187+
11 Africa GIN Guinea 8.32%
188+
12 Africa NGA Nigeria 8.09%
189+
10 Asia UZB Uzbekistan 11.12%
190+
11 Asia IRQ Iraq 10.06%
191+
12 Asia PHL Philippines 9.73%
192+
10 Europe MNE Montenegro -2.93%
193+
11 Europe SWE Sweden -3.02%
194+
12 Europe ISL Iceland -3.84%
195+
10 North America GTM Guatemala 2.71%
196+
11 North America HND Honduras 2.71%
197+
12 North America ATG Antigua and Barbuda 2.52%
198+
10 Oceania FJI Fiji 3.29%
199+
11 Oceania TUV Tuvalu 1.27%
200+
12 Oceania KIR Kiribati 0.04%
201+
10 South America ARG Argentina 5.67%
202+
11 South America PRY Paraguay -3.62%
203+
12 South America BRA Brazil -9.83%
148204

149205

150206
3\. For the year 2012, create a 3 column, 1 row report showing the percent share of gdp_per_capita for the following regions:
@@ -155,8 +211,61 @@ AUS Australia OC Oceania 2004 30464.00376
155211
------ | ------ | -------------
156212
25.0% | 25.0% | 50.0%
157213

214+
SELECT
215+
CONCAT(ROUND(((SELECT
216+
SUM(gdp_per_capita)
217+
FROM
218+
braintree.gdp_join
219+
WHERE
220+
year = 2012 AND continent_name = 'Asia') / (SELECT
221+
SUM(gdp_per_capita)
222+
FROM
223+
braintree.gdp_join
224+
WHERE
225+
year = 2012)) * 100,
226+
1),
227+
'%') AS 'Asia',
228+
CONCAT(ROUND(((SELECT
229+
SUM(gdp_per_capita)
230+
FROM
231+
braintree.gdp_join
232+
WHERE
233+
year = 2012
234+
AND continent_name = 'Europe') / (SELECT
235+
SUM(gdp_per_capita)
236+
FROM
237+
braintree.gdp_join
238+
WHERE
239+
year = 2012)) * 100,
240+
1),
241+
'%') AS 'Europe',
242+
CONCAT(ROUND(((SELECT
243+
SUM(gdp_per_capita)
244+
FROM
245+
braintree.gdp_join
246+
WHERE
247+
year = 2012 AND continent_name != 'Asia'
248+
AND continent_name != 'Europe') / (SELECT
249+
SUM(gdp_per_capita)
250+
FROM
251+
braintree.gdp_join
252+
WHERE
253+
year = 2012)) * 100,
254+
1),
255+
'%') AS 'Rest of World'
256+
257+
/* Results of This Query Below! */
258+
259+
Asia Europe Rest of World
260+
28.3% 42.2% 29.4%
261+
262+
PS:
263+
I didn't like/ understand what the question was asking and took a sum of each continents GDP per capita instead of any other metric for the sake of time. However this metric is a bit strange but this data needs more information in order to properly answer the question, EG, population of each country in the year 2012 to get GDP of each country. Otherwise, continents with more countries are skewed simply because there are more of them, not necessarily a reflection of true GDP % share.
264+
158265
4a\. What is the count of countries and sum of their related gdp_per_capita values for the year 2007 where the string 'an' (case insensitive) appears anywhere in the country name?
159266

267+
268+
160269
4b\. Repeat question 4a, but this time make the query case sensitive.
161270

162271
5\. Find the sum of gpd_per_capita by year and the count of countries for each year that have non-null gdp_per_capita where (i) the year is before 2012 and (ii) the country has a null gdp_per_capita in 2012. Your result should have the columns:

0 commit comments

Comments
 (0)