query-e013a17562821e0e1058a0961e5aa970
Former US presidents/vice-presidents, current age or age at death; years alive after last time an office held
includes incumbents with current date
by Jura1, 2020-06-20
SELECT ?person ?personLabel (MAX(?end_or_now) as ?last_date) (MAX(?age_end_or_now) as ?age_at_date) ?dob ?dod ?when ?age (?when - YEAR(?last_date) as ?yearsalivesince)
{
VALUES ?office { wd:Q11699 wd:Q11696 }
?st ps:P39 ?office .
?person wdt:P31 wd:Q5; p:P39 ?st .
OPTIONAL { ?st pq:P582 ?e }
BIND( COALESCE(?e, NOW() ) as ?end_or_now)
?person wdt:P569 ?dob .
OPTIONAL { ?person wdt:P570 ?dod } .
BIND( COALESCE( YEAR( ?dod) , YEAR(NOW()) ) as ?when )
BIND( ?when - YEAR(?dob) as ?age)
BIND(YEAR(?end_or_now)-YEAR(?dob) as ?age_end_or_now)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?person ?personLabel ?dob ?dod ?age ?when
ORDER BY DESC(?age_at_date)
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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#Former US presidents/vice-presidents, current age or age at death; years alive after last time an office held
#includes incumbents with current date
#by Jura1, 2020-06-20
SELECT ?person ?personLabel (MAX(?end_or_now) as ?last_date) (MAX(?age_end_or_now) as ?age_at_date) ?dob ?dod ?when ?age (?when - YEAR(?last_date) as ?yearsalivesince)
{
VALUES ?office { wd:Q11699 wd:Q11696 }
?st ps:P39 ?office .
?person wdt:P31 wd:Q5; p:P39 ?st .
OPTIONAL { ?st pq:P582 ?e }
BIND( COALESCE(?e, NOW() ) as ?end_or_now)
?person wdt:P569 ?dob .
OPTIONAL { ?person wdt:P570 ?dod } .
BIND( COALESCE( YEAR( ?dod) , YEAR(NOW()) ) as ?when )
BIND( ?when - YEAR(?dob) as ?age)
BIND(YEAR(?end_or_now)-YEAR(?dob) as ?age_end_or_now)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?person ?personLabel ?dob ?dod ?age ?when
ORDER BY DESC(?age_at_date)