query-c4f3766227b5ca48c35b27031d3ecada

rq turtle/ttl

For this to work, ideally ?cases and ?deaths would have a value of 1

"significant event" (P793) could store the actual dates

SELECT ?item ?itemLabel ?firstdeath ?deaths ?firstcase ?cases (?firstdeath - ?firstcase as ?diff) WHERE { # VALUES ?item { wd:Q83872271 } ?item wdt:P31 wd:Q3241045 . ?item wdt:P361 wd:Q81068910 .
?item p:P1120 [pq:P585 ?firstdeath ; ps:P1120 ?deaths ] . FILTER ( ?deaths > 0 ) FILTER NOT EXISTS { ?item p:P1120 [pq:P585 ?date_deaths2 ; ps:P1120 ?deaths2 ]. FILTER( ?firstdeath > ?date_deaths2 ) } ?item p:P1603 [pq:P585 ?firstcase ; ps:P1603 ?cases ] . FILTER ( ?cases > 0 )
FILTER NOT EXISTS { ?item p:P1603 [pq:P585 ?date_cases2 ; ps:P1603 ?cases2 ] FILTER ( ?firstcase > ?date_cases2 )
} SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }

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#>
#For this to work, ideally ?cases and ?deaths would have a value of 1
#"significant event" (P793) could store the actual dates
#
SELECT ?item ?itemLabel 
  ?firstdeath ?deaths
  ?firstcase ?cases 
  (?firstdeath - ?firstcase as ?diff) 
WHERE
{
    # VALUES ?item { wd:Q83872271 }
    ?item wdt:P31 wd:Q3241045 . 
    ?item wdt:P361 wd:Q81068910 .   
    ?item p:P1120 [pq:P585 ?firstdeath ; ps:P1120 ?deaths ] .
    FILTER ( ?deaths > 0 )
    FILTER NOT EXISTS
    {
      ?item p:P1120 [pq:P585 ?date_deaths2 ; ps:P1120 ?deaths2 ].
      FILTER( ?firstdeath > ?date_deaths2 )
    }
    ?item p:P1603 [pq:P585 ?firstcase ; ps:P1603 ?cases ] .
    FILTER ( ?cases > 0 )  
    FILTER NOT EXISTS
    { 
        ?item p:P1603 [pq:P585 ?date_cases2 ; ps:P1603 ?cases2 ] 
        FILTER ( ?firstcase > ?date_cases2 )  
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?cases"):::projected v3("?cases2") v2("?date_cases2") v7("?date_deaths2") v9("?deaths"):::projected v8("?deaths2") v10("?diff") v1("?firstcase"):::projected v6("?firstdeath"):::projected v4("?item"):::projected a3((" ")) a2((" ")) a4((" ")) a1((" ")) c10(["wd:Q81068910"]):::iri c14(["en"]):::literal c8(["wd:Q3241045"]):::iri c12(["bd:serviceParam"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?firstcase > ?date_cases2"]] e0f0 --> e0v1 e0f0 --> e0v2 e0a1 --"p:qualifier/P585"--> e0v2 e0a1 --"p:statement/P1603"--> e0v3 e0v4 --"p:P1603"--> e0a1 e0v3("?cases2"):::projected e0v2("?date_cases2"):::projected e0v1("?firstcase"):::projected e0v4("?item"):::projected e0a1((" ")):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> v2 f0 --> a1 f0 --> c1 f0 --> c2 f0 --> v3 f0 --> v4 f0 --> c3 f1[["?firstcase > ?date_cases2"]] f1 --> v1 f1 --> v2 a1 --"p:qualifier/P585"--> v2 a1 --"p:statement/P1603"--> v3 v4 --"p:P1603"--> a1 f2[["?cases > '0^^xsd:integer'"]] f2 --> v5 f3[["not "]] subgraph f3e1["Exists Clause"] e1f0[["?firstdeath > ?date_deaths2"]] e1f0 --> e1v1 e1f0 --> e1v2 e1a1 --"p:qualifier/P585"--> e1v2 e1a1 --"p:statement/P1120"--> e1v3 e1v4 --"p:P1120"--> e1a1 e1v2("?date_deaths2"):::projected e1v3("?deaths2"):::projected e1v1("?firstdeath"):::projected e1v4("?item"):::projected e1a1((" ")):::projected end f3--EXISTS--> f3e1 f3 --> v6 f3 --> v7 f3 --> a2 f3 --> c1 f3 --> c5 f3 --> v8 f3 --> v4 f3 --> c6 f4[["?firstdeath > ?date_deaths2"]] f4 --> v6 f4 --> v7 a2 --"p:qualifier/P585"--> v7 a2 --"p:statement/P1120"--> v8 v4 --"p:P1120"--> a2 f5[["?deaths > '0^^xsd:integer'"]] f5 --> v9 v4 --"p:direct/P31"--> c8 v4 --"p:direct/P361"--> c10 a3 --"p:qualifier/P585"--> v6 a3 --"p:statement/P1120"--> v9 v4 --"p:P1120"--> a3 a4 --"p:qualifier/P585"--> v1 a4 --"p:statement/P1603"--> v5 v4 --"p:P1603"--> a4 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c12 --"wikibase:language"--> c14 end bind6[/"?firstdeath - ?firstcase"/] v6 --o bind6 v1 --o bind6 bind6 --as--o v10