query-eabc885ea6722561316191546575e4e7

rq turtle/ttl

06:43, 18 August 2018 (UTC)) talk (Dipsacus fullonumI can still not run my version my the English Wikipedia with the OR filter. But for Estonian Wikipedia it gave an average of 68 years for 9188 persons in 5 seconds. -- Besides the average year is longer than 365 days because of leap years, and people living in 1800 or 1899 but not in 1801-1898 were not included. 's last version: 1) There is no need to test if the precision is less than day. There is no such datetime values in Wikidata, but if there were it would not be a problem. 2) There is no need to calculate the year with the year function before comparasion of dates. It is faster to compare datetime values directly.TagishsimonI made some optimizations on

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT (count(?p) as ?count) (avg(?age)/365.24 as ?avg_age) WHERE 
{
  ?p wdt:P31 wd:Q5 ;
      p:P569/psv:P569 [wikibase:timePrecision ?tpb ;
                       wikibase:timeValue ?birth] ;
      p:P570/psv:P570 [wikibase:timePrecision ?tpd ;
                       wikibase:timeValue ?death] .
      ?article schema:about ?p ;
               schema:isPartOf <https://da.wikipedia.org/> .
  filter(?tpb > 8 && ?tpd > 8)

#  filter(?birth < "1900-01-01T00:00:00Z"^^xsd:dateTime &&
#         ?birth >= "1800-01-01T00:00:00Z"^^xsd:dateTime)  #birth filter
#  filter(?death < "1900-01-01T00:00:00Z"^^xsd:dateTime &&
#         ?death >= "1800-01-01T00:00:00Z"^^xsd:dateTime)  #death filter
  filter(?birth < "1900-01-01T00:00:00Z"^^xsd:dateTime &&
         ?birth >= "1800-01-01T00:00:00Z"^^xsd:dateTime ||
         ?death < "1900-01-01T00:00:00Z"^^xsd:dateTime &&
         ?death >= "1800-01-01T00:00:00Z"^^xsd:dateTime) #OR filter
  bind(?death-?birth as ?age)  
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?age") v6("?article") v9("?avg_age") v1("?birth") v8("?count") v2("?death") v5("?p"):::projected v3("?tpb") v4("?tpd") a2((" ")) a1((" ")) a4((" ")) a3((" ")) c5(["wd:Q5"]):::iri c14([https://da.wikipedia.org/]):::iri f0[["(?birth < '1900-01-01T00:00:00Z^^xsd:dateTime'?birth >= '1800-01-01T00:00:00Z^^xsd:dateTime' || ?death < '1900-01-01T00:00:00Z^^xsd:dateTime'?death >= '1800-01-01T00:00:00Z^^xsd:dateTime')"]] f0 --> v1 f0 --> v2 f1[["?tpb > '8^^xsd:integer'?tpd > '8^^xsd:integer'"]] f1 --> v3 f1 --> v4 v5 --"p:direct/P31"--> c5 a1 --"wikibase:timePrecision"--> v3 a1 --"wikibase:timeValue"--> v1 v5 --"p:P569"--> a2 a2 --"p:statement/value/P569"--> a1 a3 --"wikibase:timePrecision"--> v4 a3 --"wikibase:timeValue"--> v2 v5 --"p:P570"--> a4 a4 --"p:statement/value/P570"--> a3 v6 --"schema:about"--> v5 v6 --"schema:isPartOf"--> c14 bind2[/"?death - ?birth"/] v2 --o bind2 v1 --o bind2 bind2 --as--o v7 bind5[/"count(?p)"/] v5 --o bind5 bind5 --as--o v8 bind6[/" / '365.24^^xsd:decimal'"/] null --o bind6 bind6 --as--o v9