query-fb5ffb1be83235c3e0fb634790851680
German states with their capitals, area and population
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 bd: <http://www.bigdata.com/rdf#>
SELECT ?state ?key ?stateLabel (ROUND(?areaUnrounded) AS ?area) ?population (ROUND(?population/?area) AS ?populationDensity) ?capitalLabel ?capitalPopulation (ROUND(1000*?capitalPopulation/?population)/10 AS ?ratio) WHERE {
#(ROUND(?population/10000)/100 AS ?pop)
?state wdt:P31 wd:Q1221156 .
?state wdt:P1388 ?key .
?state wdt:P1082 ?population .
?state wdt:P2046 ?areaUnrounded .
OPTIONAL{?state wdt:P36 ?capital . ?capital wdt:P1082 ?capitalPopulation}
FILTER NOT EXISTS {?state wdt:P576 ?end} .
SERVICE wikibase:label{bd:serviceParam wikibase:language "de"}
}
ORDER BY ?stateLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v9("?area"):::projected
v6("?areaUnrounded"):::projected
v7("?capital")
v8("?capitalPopulation"):::projected
v3("?end")
v4("?key"):::projected
v5("?population"):::projected
v10("?populationDensity")
v11("?ratio")
v2("?state"):::projected
v1("?stateLabel"):::projected
c11(["de"]):::literal
c9(["bd:serviceParam"]):::iri
c3(["wd:Q1221156"]):::iri
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"wdt:P576"--> e0v2
e0v2("?end"):::projected
e0v1("?state"):::projected
end
f0--EXISTS--> f0e0
f0 --> v2
f0 --> c1
f0 --> v3
v2 --"wdt:P576"--> v3
v2 --"wdt:P31"--> c3
v2 --"wdt:P1388"--> v4
v2 --"wdt:P1082"--> v5
v2 --"wdt:P2046"--> v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v2 -."wdt:P36".-> v7
v7 --"wdt:P1082"--> v8
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end
bind1[/"numeric-round(?areaUnrounded)"/]
v6 --o bind1
bind1 --as--o v9
bind2[/"numeric-round(?population / ?area)"/]
v5 --o bind2
v9 --o bind2
bind2 --as--o v10
bind3[/"numeric-round('1000^^xsd:integer' * ?capitalPopulation / ?population) / '10^^xsd:integer'"/]
v8 --o bind3
v5 --o bind3
bind3 --as--o v11