query-4623db2c31a87150e7fa702f69b6da10
German districts) and and return the state each belongs to. This is what I got so far; it doesn't work because each district can be located either directly under the state (which is fine) or below other subdivisions. (Q106658)district of Germany , (Q22865)independent city of Germany I'm trying to fetch a list of German district-level subdivisions (
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?rural_district_of_Germany ?rural_district_of_GermanyLabel ?located_in_the_administrative_territorial_entity ?located_in_the_administrative_territorial_entityLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
{ ?rural_district_of_Germany p:P31/ps:P31/wdt:P279* wd:Q22865 .
}
UNION
{ ?rural_district_of_Germany p:P31/ps:P31/wdt:P279* wd:Q106658 .
}
{ ?rural_district_of_Germany wdt:P131 ?located_in_the_administrative_territorial_entity. }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?located_in_the_administrative_territorial_entity"):::projected
v1("?rural_district_of_Germany"):::projected
a1((" "))
a2((" "))
a3((" "))
a4((" "))
c9(["wd:Q106658"]):::iri
c2(["bd:serviceParam"]):::iri
c4(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c8(["wd:Q22865"]):::iri
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c2 --"wikibase:language"--> c4
end
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v1 --"p:P31"--> a3
a3 --"p:statement/P31"--> a4
a4 --"p:direct/P279"--> c9
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v1 --"p:P31"--> a1
a1 --"p:statement/P31"--> a2
a2 --"p:direct/P279"--> c8
end
union0r <== or ==> union0l
end
v1 --"p:direct/P131"--> v2