query-0b72fab890f56b51c224bdd656f5731f
Average lifespan by occupation SELECT ?p ?occ (avg(year(?birth)) as ?birthYear) (avg(year(?death)) as ?deathYear) WHERE { ?p wdt:P31 wd:Q5 ; wdt:P106 ?occ ; p:P569/psv:P569 [ wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year wikibase:timeValue ?birth ; ] ; p:P570/psv:P570 [ wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year wikibase:timeValue ?death ; ] . } GROUP BY ?p ?occ
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/>
#Average lifespan by occupation
SELECT
?p
?occ
(avg(year(?birth)) as ?birthYear)
(avg(year(?death)) as ?deathYear)
WHERE {
?p wdt:P31 wd:Q5 ;
wdt:P106 ?occ ;
p:P569/psv:P569 [
wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year
wikibase:timeValue ?birth ;
] ;
p:P570/psv:P570 [
wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year
wikibase:timeValue ?death ;
] .
}
GROUP BY ?p ?occ
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?birth"):::projected
v5("?birthYear")
v4("?death"):::projected
v6("?deathYear")
v2("?occ"):::projected
v1("?p"):::projected
a2((" "))
a1((" "))
a4((" "))
a3((" "))
c2(["wd:Q5"]):::iri
c5(["9^^xsd:integer"]):::literal
v1 --"p:direct/P31"--> c2
v1 --"p:direct/P106"--> v2
a1 --"wikibase:timePrecision"--> c5
a1 --"wikibase:timeValue"--> v3
v1 --"p:P569"--> a2
a2 --"p:statement/value/P569"--> a1
a3 --"wikibase:timePrecision"--> c5
a3 --"wikibase:timeValue"--> v4
v1 --"p:P570"--> a4
a4 --"p:statement/value/P570"--> a3
bind2[/"average(year-from-dateTime(?birth))"/]
v3 --o bind2
bind2 --as--o v5
bind3[/"average(year-from-dateTime(?death))"/]
v4 --o bind3
bind3 --as--o v6