-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.sql
More file actions
77 lines (67 loc) · 2.87 KB
/
queries.sql
File metadata and controls
77 lines (67 loc) · 2.87 KB
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
USE world;
-- select all cities with population greater than 5 million
SELECT city.Name, city.CountryCode, country.Continent, city.Population
FROM city
JOIN country ON city.CountryCode = country.Code
WHERE city.Population > 5000000
ORDER BY (city.Population) DESC;
-- select all military bases in North America
SELECT country.Name AS Country, militarybase.Name AS MilitaryBase
FROM country
JOIN militarybase ON country.code = militarybase.countrycode
WHERE country.continent = 'North America';
-- select all langauges from each country
SELECT countrylanguage.isOfficial AS OfficialLangauge, countrylanguage.Language, country.Code AS CountryCode
FROM countrylanguage
JOIN country ON country.code = countrylanguage.countrycode;
-- select all military bases in the world
SELECT country.Name AS Country, militarybase.Name AS MilitaryBase
FROM country
JOIN militarybase ON country.code = militarybase.countrycode;
-- select all ports in the world
SELECT country.Code AS CountryCode, port.Name AS PortName
FROM country
JOIN port ON country.code = port.CountryCode;
-- show airports and runways of countries that have at least 1 airport
SELECT Country.Name AS Country_Name, Airport.Name AS Airport, Airport.Runways AS Runways
FROM Country, Airport
WHERE EXISTS (SELECT *
FROM Airport
WHERE Country.Code = Airport.CountryCode);
-- show number of countries that speak English
SELECT COUNT(Country.Name) AS English_Speaking_Countries
FROM Country
WHERE Country.Name IN (SELECT Country.Name
FROM CountryLanguage JOIN Country ON CountryLanguage.CountryCode = Country.Code
WHERE CountryLanguage.Language = 'English');
-- show military bases and surface area of countries that have at least 1 military base
SELECT Country.Name AS Country_Name, MilitaryBase.Name AS Military_Base, MilitaryBase.SurfaceArea AS Surface_Area
FROM Country, MilitaryBase
WHERE EXISTS (SELECT *
FROM MilitaryBase
WHERE Country.Code = MilitaryBase.CountryCode);
-- show ports and docks of countries that have at least 1 port
SELECT Country.Name AS Country_Name, Port.Name AS Port, Port.Docks AS Docks
FROM Country, Port
WHERE EXISTS (SELECT *
FROM Port
WHERE Country.Code = Port.CountryCode);
-- show country information for those that have at least 1 airport, 1 military base, and 1 port.
-- this information means the country could be a militaristic threat
SELECT Country.Name AS Country_Name,
Country.Continent AS Continent,
Country.Region AS Region,
Country.GovernmentForm AS Government_Form,
Country.HeadOfState AS Head_Of_State
FROM Country
WHERE (SELECT COUNT(*)
FROM Airport
WHERE Country.Code = Airport.CountryCode) > 0
AND
(SELECT COUNT(*)
FROM MilitaryBase
WHERE Country.Code = MilitaryBase.CountryCode) > 0
AND
(SELECT COUNT(*)
FROM Port
WHERE Country.Code = Port.CountryCode) > 0;