query-8ef284603ade9017e0fd9cc5eb40c786

rq turtle/ttl

All different human settlements in a country that are also in another country SELECT ?object ?objectLabel ?country ?countryLabel ?country2 ?country2Label #(COUNT(DISTINCT ?object) AS ?count) WHERE { ?object wdt:P17 ?country. #Belonging to a county ?object wdt:P17 ?country2. MINUS{?object wdt:P31/wdt:P279 wd:Q15239622.} #Filtering out all disputed territorry FILTER(STR(?country2) < STR(?country)) # use < instead of != to have each result only once MINUS { ?country wdt:P582|wdt:P576 ?ended. } #Countries have not ended or dissolved MINUS { ?country2 wdt:P582|wdt:P576 ?ended.} MINUS {?country wdt:P31/wdt:P279 wd:Q3024240} #Former countries MINUS {?country2 wdt:P31/wdt:P279 wd:Q3024240} ?object wdt:P31/wdt:P279 wd:Q486972. #Human settlements SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

GROUP BY ?country ?countryLabel ?country2 ?country2Label

ORDER BY DESC(?count)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#All different human settlements in a country that are also in another country
SELECT ?object ?objectLabel ?country ?countryLabel ?country2 ?country2Label #(COUNT(DISTINCT ?object) AS ?count)
WHERE {
  ?object wdt:P17 ?country. #Belonging to a county
  ?object wdt:P17 ?country2.
  MINUS{?object wdt:P31/wdt:P279* wd:Q15239622.} #Filtering out all disputed territorry
  FILTER(STR(?country2) < STR(?country)) # use < instead of != to have each result only once
  MINUS { ?country wdt:P582|wdt:P576 ?ended. } #Countries have not ended or dissolved
  MINUS { ?country2 wdt:P582|wdt:P576 ?ended.}
  MINUS {?country wdt:P31/wdt:P279* wd:Q3024240} #Former countries
  MINUS {?country2 wdt:P31/wdt:P279* wd:Q3024240}
  ?object wdt:P31/wdt:P279* wd:Q486972. #Human settlements
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
#GROUP BY ?country ?countryLabel ?country2 ?country2Label
#ORDER BY DESC(?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?country"):::projected v1("?country2"):::projected v4("?ended") v3("?object"):::projected a1((" ")) a2((" ")) a3((" ")) a4((" ")) c4(["wd:Q15239622"]):::iri c7(["wd:Q3024240"]):::iri c8(["wd:Q486972"]):::iri c10(["bd:serviceParam"]):::iri c12(["en"]):::literal f0[["str(?country2) < str(?country)"]] f0 --> v1 f0 --> v2 v3 --"wdt:P17"--> v2 v3 --"wdt:P17"--> v1 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; v3 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c4 end subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P576"--> v4 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P582"--> v4 end union0r <== or ==> union0l end end subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P576"--> v4 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v1 --"wdt:P582"--> v4 end union1r <== or ==> union1l end end subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v2 --"wdt:P31"--> a2 a2 --"wdt:P279"--> c7 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v1 --"wdt:P31"--> a3 a3 --"wdt:P279"--> c7 end v3 --"wdt:P31"--> a4 a4 --"wdt:P279"--> c8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end