query-594235c16f1929f38f821d317254d7cd

rq turtle/ttl

TODO

Use at

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 ?item ?itemLabel ?dob ?dod ?days ?span ?age
WHERE 
{ ?item wdt:P106 wd:Q520549.       # occupation=geologist
  ?item wdt:P569 ?dob .            # must have DoB
  ?item wdt:P570 ?dod .            # must have DoD
  bind ((?dod - ?dob) as ?days)    # date maths to get lifespan in days
  bind (floor(?days/365) as ?span) # convert to years
  FILTER (?span = 73)              # filter for 73-year olds
 BIND(year(?dob) AS ?yb)  BIND(year(?dod) AS ?yd)  
 BIND(month(?dob) AS ?mb) BIND(month(?dod) AS ?md) 
 BIND(day(?dob) AS ?db) BIND(day(?dod) AS ?dd)
 BIND(?yd-?yb AS ?age)                              # set preliminary age as year difference
 BIND(IF(?md<?mb,?age-1,?age) AS ?age)              # subtract 1 if month of death is less than month of birth...
 BIND(IF(?md=?mb && ?dd<?db, ?age-1,?age) AS ?age)  # ...or if month of death is same as month of birth but day of death is less than day of birth
 FILTER(!(?age=?span))                              # filter to show example where the age (with leap years included) differs from the span (without leap years included)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # get labels
}

Query found at