query-a9a98dcfdd2ea84287012510e93518f2
MPs who have sat in twelve or more terms
SELECT distinct ?terms ?mp ?mpLabel ?article
WHERE
{
{
SELECT ?mp (COUNT (distinct ?position) AS ?terms) WHERE {
?position wdt:P279 wd:Q16707842. # every UK MP (currently post-1832)
?mp p:P39 ?positionStatement . ?positionStatement ps:P39 ?position .
}
GROUP BY ?mp
}
optional { ?article schema:about ?mp . ?article schema:inLanguage "en" .
?article schema:isPartOf https://en.wikipedia.org/ . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
filter (?terms >= 12 ) . # twelve or more terms
}
ORDER BY desc(?terms)
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 schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# MPs who have sat in twelve or more terms
SELECT distinct ?terms ?mp ?mpLabel ?article
WHERE
{
{
SELECT ?mp (COUNT (distinct ?position) AS ?terms) WHERE {
?position wdt:P279 wd:Q16707842. # every UK MP (currently post-1832)
?mp p:P39 ?positionStatement . ?positionStatement ps:P39 ?position .
}
GROUP BY ?mp
}
optional { ?article schema:about ?mp . ?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/> . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
filter (?terms >= 12 ) . # twelve or more terms
}
ORDER BY desc(?terms)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?article"):::projected
v3("?mp"):::projected
v2("?position")
v4("?positionStatement")
v5("?terms"):::projected
c3(["wd:Q16707842"]):::iri
c8(["en"]):::literal
c10([https://en.wikipedia.org/]):::iri
c12(["bd:serviceParam"]):::iri
c14(["#91;AUTO_LANGUAGE#93;,en"]):::literal
f0[["?terms >= '12^^xsd:integer'"]]
f0 --> v5
v2 --"p:direct/P279"--> c3
v3 --"p:P39"--> v4
v4 --"p:statement/P39"--> v2
bind2[/"count(?position)"/]
v2 --o bind2
bind2 --as--o v5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v5 -."schema:about".-> v3
v5 --"schema:inLanguage"--> c8
v5 --"schema:isPartOf"--> c10
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c12 --"wikibase:language"--> c14
end