-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueries.sql
27 lines (22 loc) · 1.25 KB
/
queries.sql
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
-- Query to check successful load
SELECT * FROM university_rankings;
SELECT * FROM world_happiness;
-- Query the total number of ranked universities per country
SELECT country AS Country, COUNT(institution_name) AS "Number of Ranked Universities"
FROM university_rankings
GROUP BY country
ORDER BY "Number of Ranked Universities" DESC;
-- Join the total number of ranked universities per country with happiness ranking, sort by happiness rankings
SELECT world_happiness.overall_rank AS "Happiness Rank", world_happiness.country AS "Country", COUNT(university_rankings.country) AS "University Count"
FROM world_happiness
INNER JOIN university_rankings
ON world_happiness.country = university_rankings.country
GROUP BY world_happiness.overall_rank, world_happiness.country
ORDER BY "Happiness Rank" ASC;
-- Join the total number of ranked universities per country with happiness ranking, sort by total universities
SELECT world_happiness.overall_rank AS "Happiness Rank", world_happiness.country AS "Country", COUNT(university_rankings.country) AS "University Count"
FROM world_happiness
INNER JOIN university_rankings
ON world_happiness.country = university_rankings.country
GROUP BY world_happiness.overall_rank, world_happiness.country
ORDER BY "University Count" DESC;