query-02b035c340080a415cda26adc498f44d
Count Danish citizens by birth decade SELECT ?birth_decade (COUNT(?person) as ?persons) WHERE { ?person wdt:P31 wd:Q5. ?person wdt:P27 wd:Q35. ?person p:P569/psv:P569 [ wikibase:timeValue ?dateOfBirth; wikibase:timePrecision ?precision ]. FILTER(?precision >= "8"^^xsd:integer) # Precision is decade or smaller BIND(SUBSTR(STR(?dateOfBirth),1,3) as ?birth_decade) } GROUP BY ?birth_decade ORDER BY ASC(?birth_decade)
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
# Count Danish citizens by birth decade
SELECT ?birth_decade (COUNT(?person) as ?persons)
WHERE
{
?person wdt:P31 wd:Q5.
?person wdt:P27 wd:Q35.
?person p:P569/psv:P569 [
wikibase:timeValue ?dateOfBirth;
wikibase:timePrecision ?precision
].
FILTER(?precision >= "8"^^xsd:integer) # Precision is decade or smaller
BIND(SUBSTR(STR(?dateOfBirth),1,3) as ?birth_decade)
}
GROUP BY ?birth_decade
ORDER BY ASC(?birth_decade)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?birth_decade"):::projected
v4("?dateOfBirth")
v3("?person"):::projected
v5("?persons")
v2("?precision")
a2((" "))
a1((" "))
c3(["wd:Q5"]):::iri
c5(["wd:Q35"]):::iri
f0[["?precision >= '8^^xsd:integer'"]]
f0 --> v2
v3 --"p:direct/P31"--> c3
v3 --"p:direct/P27"--> c5
a1 --"wikibase:timeValue"--> v4
a1 --"wikibase:timePrecision"--> v2
v3 --"p:P569"--> a2
a2 --"p:statement/value/P569"--> a1
bind1[/"substring(str(?dateOfBirth),'1^^xsd:integer','3^^xsd:integer')"/]
v4 --o bind1
bind1 --as--o v5
bind3[/"count(?person)"/]
v3 --o bind3
bind3 --as--o v5