query-f3c90c7a0d5a67f8e85f0d54c2e76dc9
UK Parliament constituencies and the number of male & female MPs they have elected since 1997
SELECT DISTINCT ?constituency ?constituencyLabel ?created ?dissolved ?men_elected ?women_elected ?total
{
?constituency wdt:P31 wd:Q27971968 .
filter not exists { ?constituency wdt:P576 ?end . FILTER (?end <= "1997-05-01T00:00:00Z"^^xsd:dateTime) . }
optional { ?constituency wdt:P576 ?end . bind(year(?end) as ?dissolved) . }
optional { ?constituency wdt:P571 ?start . bind(year(?start) as ?created) . }
# find all constituencies, omit any dissolved before 1997
optional { SELECT ?constituency (COUNT (distinct ?man) AS ?men_elected) WHERE {
?constituency wdt:P31 wd:Q27971968 .
?man p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start .
?man wdt:P21 wd:Q6581097 . FILTER (?start >= "1997-05-01T00:00:00Z"^^xsd:dateTime) .
} GROUP BY ?constituency }
# find and count all men elected (optional in case 0), omit any elected before 1997
optional { SELECT ?constituency (COUNT (distinct ?woman) AS ?women_elected) WHERE {
?constituency wdt:P31 wd:Q27971968 .
?woman p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start .
?woman wdt:P21 wd:Q6581072 . FILTER (?start >= "1997-05-01T00:00:00Z"^^xsd:dateTime) .
} GROUP BY ?constituency }
# find and count all women elected (optional in case 0), omit any elected before 1997
{ SELECT ?constituency (COUNT (distinct ?mp) AS ?total) WHERE {
?constituency wdt:P31 wd:Q27971968 .
?mp p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start .
FILTER (?start >= "1997-05-01T00:00:00Z"^^xsd:dateTime) .
} GROUP BY ?constituency }
# find and count all people elected, omit any elected before 1997
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
ORDER BY ?men_elected ?women_elected
Use at
- https://query.wikidata.org/sparql
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 male & female MPs they have elected since 1997
SELECT DISTINCT ?constituency ?constituencyLabel ?created ?dissolved ?men_elected ?women_elected ?total
{
?constituency wdt:P31 wd:Q27971968 .
filter not exists { ?constituency wdt:P576 ?end . FILTER (?end <= "1997-05-01T00:00:00Z"^^xsd:dateTime) . }
optional { ?constituency wdt:P576 ?end . bind(year(?end) as ?dissolved) . }
optional { ?constituency wdt:P571 ?start . bind(year(?start) as ?created) . }
# find all constituencies, omit any dissolved before 1997
optional { SELECT ?constituency (COUNT (distinct ?man) AS ?men_elected) WHERE {
?constituency wdt:P31 wd:Q27971968 .
?man p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start .
?man wdt:P21 wd:Q6581097 . FILTER (?start >= "1997-05-01T00:00:00Z"^^xsd:dateTime) .
} GROUP BY ?constituency }
# find and count all men elected (optional in case 0), omit any elected before 1997
optional { SELECT ?constituency (COUNT (distinct ?woman) AS ?women_elected) WHERE {
?constituency wdt:P31 wd:Q27971968 .
?woman p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start .
?woman wdt:P21 wd:Q6581072 . FILTER (?start >= "1997-05-01T00:00:00Z"^^xsd:dateTime) .
} GROUP BY ?constituency }
# find and count all women elected (optional in case 0), omit any elected before 1997
{ SELECT ?constituency (COUNT (distinct ?mp) AS ?total) WHERE {
?constituency wdt:P31 wd:Q27971968 .
?mp p:P39 ?positionStatement . ?positionStatement pq:P768 ?constituency . ?positionStatement pq:P580 ?start .
FILTER (?start >= "1997-05-01T00:00:00Z"^^xsd:dateTime) .
} GROUP BY ?constituency }
# find and count all people elected, omit any elected before 1997
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}
ORDER BY ?men_elected ?women_elected