query-e391c6f235b7ea6d9b56ebc9be36b1ad

rq turtle/ttl

German rural municipalities without a rural yet

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#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>

SELECT DISTINCT ?muni ?key ?muniLabel ?ruralKey ?ruralLabel WHERE {
  ?muni p:P31 ?instanceBlock . 
  ?instanceBlock v:P31 ?instance .
  {?instance wdt:P279+ wd:Q262166} UNION {BIND (wd:Q262166 AS ?instance)}
  FILTER NOT EXISTS {?instanceBlock pq:P582 ?end} .
  ?muni wdt:P439 ?key .
  BIND(SUBSTR(?key,1,5) AS ?ruralKey) .
  ?rural wdt:P440 ?ruralKey .
  FILTER NOT EXISTS {?muni wdt:P131 ?rural}
  FILTER NOT EXISTS {?muni wdt:P31 wd:Q22865}
  SERVICE wikibase:label{bd:serviceParam wikibase:language "de"}
}
ORDER BY ?key

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?end") v7("?instance") v4("?instanceBlock") v1("?key"):::projected v2("?muni"):::projected v3("?rural") v7("?ruralKey"):::projected c14(["de"]):::literal c2(["wd:Q22865"]):::iri c12(["bd:serviceParam"]):::iri c8(["wd:Q262166"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:direct/P31"--> e0c2 e0v1("?muni"):::projected e0c2(["wd:Q22865"]):::iri end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> c2 v2 --"p:direct/P31"--> c2 f1[["not "]] subgraph f1e1["Exists Clause"] e1v1 --"p:direct/P131"--> e1v2 e1v1("?muni"):::projected e1v2("?rural"):::projected end f1--EXISTS--> f1e1 f1 --> v2 f1 --> c3 f1 --> v3 v2 --"p:direct/P131"--> v3 f2[["not "]] subgraph f2e2["Exists Clause"] e2v1 --"p:qualifier/P582"--> e2v2 e2v2("?end"):::projected e2v1("?instanceBlock"):::projected end f2--EXISTS--> f2e2 f2 --> v4 f2 --> c4 f2 --> v5 v4 --"p:qualifier/P582"--> v5 v2 --"p:P31"--> v4 v4 --"p:statement/P31"--> v7 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; bind3[/"'wd:Q262166'"/] bind3 --as--o v7 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v7 --"p:direct/P279"--> c8 end union0r <== or ==> union0l end v2 --"p:direct/P439"--> v1 bind4[/"substring(?key,'1^^xsd:integer','5^^xsd:integer')"/] v1 --o bind4 bind4 --as--o v7 v3 --"p:direct/P440"--> v7 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c12 --"wikibase:language"--> c14 end