query-e013a17562821e0e1058a0961e5aa970

rq turtle/ttl

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

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)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v10("?age"):::projected v13("?age_at_date") v11("?age_end_or_now"):::projected v7("?dob"):::projected v8("?dod"):::projected v5("?e") v6("?end_or_now"):::projected v12("?last_date"):::projected v2("?office") v4("?person"):::projected v3("?st") v9("?when"):::projected v13("?yearsalivesince") c9(["bd:serviceParam"]):::iri c3(["wd:Q5"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/VALUES ?office/] bind0-->v2 bind00(["wd:Q11699"]) bind00 --> bind0 bind01(["wd:Q11696"]) bind01 --> bind0 v3 --"p:statement/P39"--> v2 v4 --"p:direct/P31"--> c3 v4 --"p:P39"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:qualifier/P582".-> v5 end bind1[/"?eNOW()"/] v5 --o bind1 bind1 --as--o v6 v4 --"p:direct/P569"--> v7 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P570".-> v8 end bind2[/"year-from-dateTime(?dod)year-from-dateTime(NOW())"/] v8 --o bind2 bind2 --as--o v9 bind3[/"?when - year-from-dateTime(?dob)"/] v9 --o bind3 v7 --o bind3 bind3 --as--o v10 bind4[/"year-from-dateTime(?end_or_now) - year-from-dateTime(?dob)"/] v6 --o bind4 v7 --o bind4 bind4 --as--o v11 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end bind7[/"max(?end_or_now)"/] v6 --o bind7 bind7 --as--o v12 bind8[/"max(?age_end_or_now)"/] v11 --o bind8 bind8 --as--o v13 bind9[/"?when - year-from-dateTime(?last_date)"/] v9 --o bind9 v12 --o bind9 bind9 --as--o v13