query-e06fd0e89705d186096f59a6f61432bd
Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date Added 2020-07
All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel WITH { # Persons who is/were president of USA SELECT ?president ?presidentLabel ?president_enddate ?president_birthdate ?president_deathdate WHERE { ?president wdt:P31 wd:Q5. ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?president_enddate. ?president wdt:P569 ?president_birthdate. OPTIONAL { ?president wdt:P570 ?president_deathdate. } ?president rdfs:label ?presidentLabel. FILTER (LANG(?presidentLabel) = "en") } } AS %presidents WITH { # Dates where who is oldest living expresident can change SELECT DISTINCT ?date WHERE { { INCLUDE %presidents BIND(?president_enddate + "P1D"^^xsd:duration AS ?date) } UNION { INCLUDE %presidents BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date) } } } AS %dates WITH { # Find the age for all living expresidents for each value of ?date SELECT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates INCLUDE %presidents FILTER (?president_enddate < ?date) # Must have become expresident FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living BIND (?date - ?president_birthdate AS ?age) } } AS %ages WITH { # Find the oldest age for a living expresident for each value of ?date SELECT ?date (MAX(?age) AS ?oldest) WHERE { INCLUDE %ages } GROUP BY ?date } AS %oldest WITH { SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate WHERE { INCLUDE %dates OPTIONAL { INCLUDE %ages INCLUDE %oldest FILTER (?age = ?oldest) } } } AS %result WHERE { # A result is a change from the previous date if ?president's presidency ended the day before ?date, # or if an older expresident died the day before ?date. Filter out results that don't fulfill this. INCLUDE %result BIND (?date - "P1D"^^xsd:duration AS ?day_before) FILTER ( ! BOUND(?president)|| EXISTS { ?president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?day_before. } || EXISTS { ?other_president wdt:P31 wd:Q5. ?other_president p:P39 ?president_statement. ?president_statement ps:P39 wd:Q11696. ?president_statement pq:P582 ?other_president_end. ?other_president wdt:P569 ?other_president_birthdate. ?other_president wdt:P570 ?day_before. FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest FILTER (?other_president_end < ?day_before) # other president died as expresident } ) } ORDER BY ?date
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
# Added 2020-07
# All persons who have been the oldest living US ex-president with dates in chronological order
SELECT DISTINCT ?date ?president ?presidentLabel
WHERE
{
# A result is a change from the previous date if ?president's presidency ended the day before ?date,
# or if an older expresident died the day before ?date. Filter out results that don't fulfill this.
{
SELECT DISTINCT ?date ?age ?president ?presidentLabel ?president_birthdate
WHERE
{
{
# Dates where who is oldest living expresident can change
SELECT DISTINCT ?date
WHERE
{
{
INCLUDE %presidents
BIND(?president_enddate + "P1D"^^xsd:duration AS ?date)
}
UNION
{
INCLUDE %presidents
BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date)
}
}
} OPTIONAL
{
{
# Find the age for all living expresidents for each value of ?date
SELECT ?date ?age ?president ?presidentLabel ?president_birthdate
WHERE
{
{
# Dates where who is oldest living expresident can change
SELECT DISTINCT ?date
WHERE
{
{
INCLUDE %presidents
BIND(?president_enddate + "P1D"^^xsd:duration AS ?date)
}
UNION
{
INCLUDE %presidents
BIND(?president_deathdate + "P1D"^^xsd:duration AS ?date)
}
}
} INCLUDE %presidents
FILTER (?president_enddate < ?date) # Must have become expresident
FILTER IF(BOUND(?president_deathdate), ?president_deathdate >= ?date, true) # Must still be living
BIND (?date - ?president_birthdate AS ?age)
}
}
{
# Find the oldest age for a living expresident for each value of ?date
SELECT ?date (MAX(?age) AS ?oldest)
WHERE
{
INCLUDE %ages
}
GROUP BY ?date
} FILTER (?age = ?oldest)
}
}
} BIND (?date - "P1D"^^xsd:duration AS ?day_before)
FILTER
(
! BOUND(?president)||
EXISTS
{
?president p:P39 ?president_statement.
?president_statement ps:P39 wd:Q11696.
?president_statement pq:P582 ?day_before.
} ||
EXISTS
{
?other_president wdt:P31 wd:Q5.
?other_president p:P39 ?president_statement.
?president_statement ps:P39 wd:Q11696.
?president_statement pq:P582 ?other_president_end.
?other_president wdt:P569 ?other_president_birthdate.
?other_president wdt:P570 ?day_before.
FILTER (?other_president_birthdate < ?president_birthdate) # Other president is oldest
FILTER (?other_president_end < ?day_before) # other president died as expresident
}
)
}
ORDER BY ?date
Query found at
- https://www.wikidata.org/wiki/User:Legoktm/long-sparql
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/en
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/es
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/fr
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/hy
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/ja
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/nl
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/sv
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/tr
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/uk
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/zh