query-a2e8babf21c4b678447cf93d40365178

rq turtle/ttl

Number of German urban municipalities by state

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 (?prefix AS ?key) ?stateLabel (COUNT(?key) AS ?count) WHERE{
SELECT DISTINCT ?stateLabel ?muni ?prefix ?key WHERE {
  ?muni p:P31 ?instanceBlock . 
  ?instanceBlock v:P31 wd:Q42744322 .
  FILTER NOT EXISTS {?instanceBlock pq:P582 ?end} .
  ?muni wdt:P439 ?key .
  BIND (SUBSTR(?key,1,2) AS ?prefix) .
  ?state wdt:P1388 ?prefix
  SERVICE wikibase:label{bd:serviceParam wikibase:language "de"}
}
}
GROUP BY ?prefix ?stateLabel
ORDER BY DESC(?count) ?stateLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?count") v4("?end") v3("?instanceBlock") v9("?key"):::projected v5("?muni") v7("?prefix"):::projected v8("?state") v2("?stateLabel"):::projected c10(["de"]):::literal c8(["bd:serviceParam"]):::iri c4(["wd:Q42744322"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v2("?end"):::projected e0v1("?instanceBlock"):::projected end f0--EXISTS--> f0e0 f0 --> v3 f0 --> c1 f0 --> v4 v3 --"p:qualifier/P582"--> v4 v5 --"p:P31"--> v3 v3 --"p:statement/P31"--> c4 v5 --"p:direct/P439"--> v9 bind1[/"substring(?key,'1^^xsd:integer','2^^xsd:integer')"/] v9 --o bind1 bind1 --as--o v7 v8 --"p:direct/P1388"--> v7 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end bind3[/"?prefix"/] v7 --o bind3 bind3 --as--o v9 bind4[/"count(?key)"/] v9 --o bind4 bind4 --as--o v9