query-3fa5df366bc19164e9efa14577e33d76

rq turtle/ttl

.(Q47566)United States presidential election To start this off, let's look at how we could use WD to see if a government gets reelected or not. Using the US presidential elections as an example, you could look at all instances of

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 ?a  ?aLabel ?aDescription ?ordinal ?d ?party ?partyLabel ?d1 ?party1 (?party = ?party1 as ?same)
{
  {
  SELECT ?a  ?aLabel ?aDescription ?ordinal ?d ?party ?partyLabel (MAX(?d1) as ?d1) 
  WHERE 
  {
    ?a wdt:P31 wd:Q47566 .
    ?a wdt:P585 ?d . 
    ?a wdt:P991 / wdt:P102 ?party .
    { SELECT ?prevd ?d1 { ?prevd wdt:P31 wd:Q47566 ; wdt:P585 ?d1 .  }   
    }
    FILTER(?d1 < ?d) 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }
  GROUP BY ?a  ?aLabel ?aDescription ?ordinal ?d ?party ?partyLabel 
  }
  ?previous wdt:P31 wd:Q47566; wdt:P585 ?d1 ; wdt:P991 / wdt:P102 ?party1 .  
}
ORDER BY DESC(?d)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?a"):::projected v1("?d"):::projected v6("?d1"):::projected v4("?party"):::projected v7("?party1"):::projected v5("?prevd") v6("?previous") v8("?same") a1((" ")) a2((" ")) c7(["bd:serviceParam"]):::iri c2(["wd:Q47566"]):::iri c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?d1 < ?d"]] f0 --> v6 f0 --> v1 v3 --"wdt:P31"--> c2 v3 --"wdt:P585"--> v1 v3 --"wdt:P991"--> a1 a1 --"wdt:P102"--> v4 v5 --"wdt:P31"--> c2 v5 --"wdt:P585"--> v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end bind2[/"max(?d1)"/] v6 --o bind2 bind2 --as--o v6 v6 --"wdt:P31"--> c2 v6 --"wdt:P585"--> v6 v6 --"wdt:P991"--> a2 a2 --"wdt:P102"--> v7 bind3[/"?party = ?party1"/] v4 --o bind3 v7 --o bind3 bind3 --as--o v8