query-b7335c823e42dc39b3d813131aa29cd7

rq turtle/ttl

UK Parliament constituencies and the number of MPs who died in office

analysis restricted to "since 1929"

SELECT DISTINCT ?constituency ?constituencyLabel ?startyear ?endyear ?died ?total ?percent_died_in_office { ?constituency wdt:P31 wd:Q27971968 . optional { ?constituency wdt:P571 ?start . bind(year(?start) as ?startyear)} optional { ?constituency wdt:P576 ?end . bind(year(?end) as ?endyear)} # find all constituencies { SELECT ?constituency (COUNT (distinct ?member) AS ?died) WHERE { ?constituency wdt:P31 wd:Q27971968 . ?member p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P1534 wd:Q5247364 . ?positionStatement pq:P580 ?start . FILTER (?start >= "1929-01-01T00:00:00Z"^^xsd:dateTime) . } GROUP BY ?constituency }
# find and count all people who died in office { SELECT ?constituency (COUNT (distinct ?member) AS ?total) WHERE { ?constituency wdt:P31 wd:Q27971968 . ?member p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start . FILTER (?start >= "1929-01-01T00:00:00Z"^^xsd:dateTime) . } GROUP BY ?constituency } # find and count all people elected SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' } bind ((?died/?total)*100 as ?percent_died_in_office) } ORDER BY desc(?percent_died_in_office)

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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# UK Parliament constituencies and the number of MPs who died in office
# analysis restricted to "since 1929"
#
SELECT DISTINCT ?constituency ?constituencyLabel ?startyear ?endyear ?died ?total ?percent_died_in_office
{
 ?constituency wdt:P31 wd:Q27971968 . 
  optional { ?constituency wdt:P571 ?start . bind(year(?start) as ?startyear)}
  optional { ?constituency wdt:P576 ?end . bind(year(?end) as ?endyear)}
 # find all constituencies
  { SELECT ?constituency (COUNT (distinct ?member) AS ?died) WHERE {
      ?constituency wdt:P31 wd:Q27971968 . 
      ?member p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P1534 wd:Q5247364 .
      ?positionStatement pq:P580 ?start . FILTER (?start >= "1929-01-01T00:00:00Z"^^xsd:dateTime) . 
    } GROUP BY ?constituency }  
  # find and count all people who died in office 
  { SELECT ?constituency (COUNT (distinct ?member) AS ?total) WHERE {
      ?constituency wdt:P31 wd:Q27971968 . 
      ?member p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency .
      ?positionStatement pq:P580 ?start . FILTER (?start >= "1929-01-01T00:00:00Z"^^xsd:dateTime) . 
    } GROUP BY ?constituency }
  # find and count all people elected 
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
  bind ((?died/?total)*100 as ?percent_died_in_office)
}
ORDER BY desc(?percent_died_in_office)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?constituency"):::projected v9("?died"):::projected v5("?end") v6("?endyear"):::projected v7("?member") v11("?percent_died_in_office"):::projected v8("?positionStatement") v3("?start") v4("?startyear"):::projected v10("?total"):::projected c2(["wd:Q27971968"]):::iri c14(["en"]):::literal c9(["wd:Q5247364"]):::iri c12(["bd:serviceParam"]):::iri v2 --"p:direct/P31"--> c2 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P571".-> v3 bind0[/"year-from-dateTime(?start)"/] v3 --o bind0 bind0 --as--o v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P576".-> v5 bind1[/"year-from-dateTime(?end)"/] v5 --o bind1 bind1 --as--o v6 end f2[["?start >= '1929-01-01T00:00:00Z^^xsd:dateTime'"]] f2 --> v3 v2 --"p:direct/P31"--> c2 v7 --"p:P39"--> v8 v8 --"p:qualifier/P768"--> v2 v8 --"p:qualifier/P1534"--> c9 v8 --"p:qualifier/P580"--> v3 bind4[/"count(?member)"/] v7 --o bind4 bind4 --as--o v9 f5[["?start >= '1929-01-01T00:00:00Z^^xsd:dateTime'"]] f5 --> v3 v2 --"p:direct/P31"--> c2 v7 --"p:P39"--> v8 v8 --"p:qualifier/P768"--> v2 v8 --"p:qualifier/P580"--> v3 bind7[/"count(?member)"/] v7 --o bind7 bind7 --as--o v10 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c12 --"wikibase:language"--> c14 end bind8[/"?died / ?total * '100^^xsd:integer'"/] v9 --o bind8 v10 --o bind8 bind8 --as--o v11