linfo2172-databases/P4/queries.cyp

68 lines
1.8 KiB
Plaintext

# 1
MATCH (:Country {name:"Greece"})-[:Borders]->(c:Country)<-[e:Encompasses]-(k:Continent WHERE k.name <> 'Europe' OR e.percentage <> "100.0")
RETURN DISTINCT c.name;
# 2 - VALID
MATCH (:Country {name:"China"})-[:Borders]->(c:Country)-[:Borders]->(c2:Country)-[:Borders]->(:Country {name:"China"})
WHERE c.name < c2.name
RETURN c.name, c2.name;
# 3
MATCH (:Continent {name:"Europe"})-[:Encompasses {percentage:"100.0"}]->(c:Country)-[:Borders]->(:Country)<-[e:Encompasses]-(k:Continent WHERE k.name <> "Europe" OR e.percentage <> "100.0")
RETURN DISTINCT c.name;
# 4
MATCH (:Country {name:"Turkey"})-[:Borders *..2]->(c:Country WHERE c.name <> "Turkey")<-[:Encompasses]-(k:Continent {name:"Asia"})
RETURN DISTINCT c.name
ORDER BY c.name;
# 5 - VALID
MATCH (:Continent {name:"Europe"})-[:Encompasses {percentage: "100.0"}]->(c:Country)
WITH c, COUNT {(c)-[:Borders]->()} AS degree
RETURN c.name, degree
ORDER BY degree DESC;
# 6 - VALID
MATCH (c:Country)
WITH c, COUNT{(c)-[:Borders]->()} AS degree
RETURN c.name, degree
ORDER BY degree DESC
LIMIT 1;
# 7 - VALID
MATCH p=shortestPath((:Country {name:"Belgium"})-[:Borders *]->(:Country {name:"China"}))
RETURN p;
# 8
MATCH p=shortestPath((:Country {name:"Belgium"})-[:Borders *]->(d:Country WHERE d.name <> "Belgium"))
RETURN d.name
ORDER BY length(p) DESC
LIMIT 1
;
# 9 - VALID
MATCH (c:Country)-[:Borders]->(c1:Country)
MATCH (c:Country)-[:Borders]->(c2:Country)
MATCH (c:Country)-[:Borders]->(c3:Country)
MATCH (c1:Country)-[:Borders]->(c2:Country)-[:Borders]->(c3:Country)-[:Borders]->(c1:Country)
WITH c, COUNT {(c)-[:Borders]->()} AS degree
WHERE degree = 3
RETURN DISTINCT c.name;
# 10 - VALID
MATCH (:Continent {name:"Europe"})-[:Encompasses]->(c:Country)
WHERE NOT (c:Country)-[:Borders *1..3]->(:Country)<-[:Encompasses]-(:Continent {name:"Asia"})
RETURN c.name
ORDER BY c.name;