query-cd5c79390863fd568ca9cfef4d6a0e1c

rq turtle/ttl

]reply[20:48, 19 June 2020 (UTC)) talk (OravrattasBut getting from that to who was the oldest still living at the relevant points is hurting my brain too much. Anyone able to put something together? --: I can't get there, but here's a start:Oravrattas@

Use at

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/>
SELECT ?day ((count(?pres)+1) as ?n) WHERE 
{
 { SELECT distinct ?day WHERE {
  { ?m wdt:P31 wd:Q5 . ?m p:P39 ?st . ?st ps:P39 wd:Q11696 . ?m wdt:P570 ?day } union
  { ?m wdt:P31 wd:Q5 . ?m p:P39 ?st . ?st ps:P39 wd:Q11696 . ?st pq:P580 ?day } union
  { ?m wdt:P31 wd:Q5 . ?m p:P39 ?st . ?st ps:P39 wd:Q11696 . ?st pq:P582 ?day } } }
  optional { ?pres wdt:P31 wd:Q5 . ?pres p:P39 ?st . ?st ps:P39 wd:Q11696 . ?st pq:P582 ?end .
             optional { ?pres wdt:P570 ?died } . filter (COALESCE(?died, NOW()) > ?day ) .
             filter (?day >= ?end ) . }
} group by ?day order by ?day

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?day"):::projected v2("?died") v3("?end") v4("?m") v7("?n") v6("?pres") v5("?st") c2(["wd:Q5"]):::iri c5(["wd:Q11696"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P31"--> c2 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> c5 v5 --"p:qualifier/P582"--> v1 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P31"--> c2 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> c5 v5 --"p:qualifier/P580"--> v1 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P31"--> c2 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> c5 v4 --"p:direct/P570"--> v1 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P31".-> c2 v6 --"p:P39"--> v5 v5 --"p:statement/P39"--> c5 v5 --"p:qualifier/P582"--> v3 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P570".-> v2 end end bind1[/" + '+1^^xsd:integer'"/] null --o bind1 bind1 --as--o v7