linfo2172-databases/P1/queries.rel

147 lines
3.7 KiB
Plaintext

// Question 1
Mountain { name }
// Question 2
(CountryCovid WHERE year=2021 AND month=3 AND total_cases>10000) { country }
// Question 3
WITH (
A := Province WHERE area < 200.0,
B := Encompasses WHERE continent="Europe",
C := (A JOIN B) RENAME { name AS province, country AS code },
D := (C JOIN Country { name, code }) RENAME { name AS country }
): D { province, country }
// Question 4
WITH (
A := (Encompasses WHERE continent = "Europe") RENAME { country AS code },
B := Country JOIN A,
C := (CountryCovid WHERE year=2022 AND month=12 AND total_deaths>10000) RENAME { country as code },
D := (B JOIN C) RENAME { name AS country }
): D
{ country, population, total_deaths }
// Question 5
(
(Independence RENAME { country AS code })
JOIN Country
)
{ name, independence }
// Question 6
WITH (
A := (Borders WHERE country2="TJ" OR country2 = "IND") RENAME { country1 AS code },
B := Country JOIN A,
C := SUMMARIZE B BY { name, code } : { n := COUNT() },
D := C WHERE n >= 2
): D { code, name }
// Question 7
(
SUMMARIZE
(
(
Country
JOIN
(GeoMountain RENAME { country AS code })
)
JOIN
(
(Mountain RENAME { name AS mountain })
WHERE mountains = "Alps" AND height > 4000.0
)
)
BY { capital }: { n := COUNT() }
)
{ capital }
// Question 8
(
Country
NOT MATCHING
(Language RENAME { country AS code, name AS language })
)
{ code, name }
// Question 9
WITH (
A := Mountain RENAME { name AS mountain },
B := (A JOIN GeoMountain) { country, mountain, mountains },
C := SUMMARIZE B BY { mountain, mountains }: { n := COUNT() },
D := C WHERE n > 1
): D
{ mountains }
// Question 10
WITH (
A := (CountryCovid RENAME { country AS code }) WHERE total_deaths > 10000,
B := Country JOIN A,
C := B JOIN ((Province { name }) RENAME { name AS capital }),
D := SUMMARIZE D BY { capital }: { n := COUNT() },
E := D RENAME { capital AS name }
): E
{ name }
// Question 11
WITH (
A := (Borders WHERE country1="USA") { country1, country2 },
B := A JOIN (Borders RENAME { country2 AS code, country1 AS country2 }),
C := B { code },
D := (Borders WHERE country1="USA") { country2 } RENAME { country2 AS code },
E := C UNION D,
F := E WHERE code <> "USA",
G := F JOIN Country
): G
{ name }
// Question 12
SUMMARIZE CountryCovid { country } BY { }: { cnt := COUNT() }
// Question 13
WITH (
A := Country RENAME { code AS country },
B := (A NOT MATCHING CountryCovid) { country },
C := (CountryCovid WHERE year = 2021 AND month = 12 AND total_cases = 0) { country },
D := (B UNION C) RENAME { country AS country1 },
E := (D JOIN Borders) RENAME { country1 AS code },
G := (E JOIN Country) RENAME { name AS country1 },
H := (G { country1, country2 }) RENAME { country2 AS code },
I := (H JOIN Country) RENAME { name AS country2 }
): I
{ country1, country2 }
// Question 14
(Language WHERE percentage = MAX((Language RENAME {country AS code}) WHERE code=country, percentage)) {country, name}
// Question 15
WITH (
A := Borders RENAME { country1 AS c1, country2 AS c2 },
B := Borders RENAME { country1 AS c2, country2 AS c1 },
C := A NOT MATCHING B
): C
{ c1, c2 }
// Question 16
WITH (
A := SUMMARIZE Language BY { country }: { lang_p := SUM(percentage) },
B := A WHERE lang_p < 99.0,
C := (EXTEND B: { unknown_lang_p := 100.0 - lang_p }) { country, unknown_lang_p },
C2 := C RENAME { country AS code },
D := Language { country } RENAME { country AS code },
E := Country { code } NOT MATCHING D,
F := EXTEND E: { unknown_lang_p := 100.0 },
G := C2 UNION F,
H := G JOIN Country
): H
{ name, unknown_lang_p }