query-6a3f6b74e136874ef0e18325008cce64
Graph of the number of MPs who died in office by year
Use at
- https://query.wikidata.org/sparql
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#>
# How many MPs died in office, each year 1832-date?
# Data pre-WW2 is still a bit flaky on exact death dates,
# probably a bit more reliable after that
SELECT ?year ?diedcount
#defaultView:BarChart
WHERE {
{
# count of MPs who died in office in each parliament
SELECT ?year (COUNT(DISTINCT ?mp) AS ?died) WHERE {
?membership wdt:P279 wd:Q16707842 . # all UK MPs
?mp p:P39 ?positionStatement . ?positionStatement ps:P39 ?membership .
?positionStatement pq:P1534 wd:Q5247364 . # ie only those coded as end cause: death in office
?mp wdt:P570 ?died .
BIND(STR(YEAR(?died)) AS ?year)
}
GROUP BY ?year
} BIND(?died AS ?diedcount)
# add labels
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?year
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?died")
v6("?diedcount"):::projected
v2("?membership")
v3("?mp")
v4("?positionStatement")
v6("?year"):::projected
c9(["bd:serviceParam"]):::iri
c2(["wd:Q16707842"]):::iri
c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c6(["wd:Q5247364"]):::iri
v2 --"p:direct/P279"--> c2
v3 --"p:P39"--> v4
v4 --"p:statement/P39"--> v2
v4 --"p:qualifier/P1534"--> c6
v3 --"p:direct/P570"--> v6
bind0[/"str(year-from-dateTime(?died))"/]
v6 --o bind0
bind0 --as--o v6
bind2[/"count(?mp)"/]
v3 --o bind2
bind2 --as--o v6
bind3[/"?died"/]
v6 --o bind3
bind3 --as--o v6
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end