query-c6e385b559e6b7e2bd6cbab3d1049a4f

rq turtle/ttl

Einwohner pro Bundesland und Durchschnitt pro Gemeinde

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 ?state ?stateLabel (COUNT(?muni) AS ?munis) (SUM(?pop) AS ?population) (ROUND(AVG(?pop)) AS ?average) WHERE {
  VALUES ?instance {wd:Q262166 wd:Q42744322} .
  ?muni wdt:P439 ?key .
  ?muni p:P31 ?instanceBlock . 
  ?instanceBlock v:P31 ?instance .
  FILTER NOT EXISTS {?instanceBlock pq:P582 ?end} .
  ?muni wdt:P1082 ?pop .
  BIND (SUBSTR(?key,1,2) AS ?prefix) . ?state wdt:P1388 ?prefix
  SERVICE wikibase:label{bd:serviceParam wikibase:language "de"}
}
GROUP BY ?state ?stateLabel
ORDER BY ?average

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v12("?average") v3("?end") v4("?instance") v2("?instanceBlock") v6("?key") v5("?muni"):::projected v10("?munis") v7("?pop"):::projected v11("?population") v8("?prefix") v9("?state"):::projected c10(["de"]):::literal c8(["bd:serviceParam"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v2("?end"):::projected e0v1("?instanceBlock"):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> v3 v2 --"p:qualifier/P582"--> v3 bind1[/VALUES ?instance/] bind1-->v4 bind10(["wd:Q262166"]) bind10 --> bind1 bind11(["wd:Q42744322"]) bind11 --> bind1 v5 --"p:direct/P439"--> v6 v5 --"p:P31"--> v2 v2 --"p:statement/P31"--> v4 v5 --"p:direct/P1082"--> v7 bind2[/"substring(?key,'1^^xsd:integer','2^^xsd:integer')"/] v6 --o bind2 bind2 --as--o v8 v9 --"p:direct/P1388"--> v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind6[/"count(?muni)"/] v5 --o bind6 bind6 --as--o v10 bind7[/"sum(?pop)"/] v7 --o bind7 bind7 --as--o v11 bind8[/"numeric-round()"/] null --o bind8 bind8 --as--o v12