query-7c3ecfef88d1e148711b6d9acd781eea
: The query by Jura is a good starting point, but it counts parliament member multiple times if they have multiple position statement for a certain year. For instance all reelected members are counted twice in the election years. That can be difficult to see because the graph is shown as percentages. To fix that I made another subquery (called %memberyears) with the DISTINCT keyword in the SELECT clause. If you remove that DISTINCT you will see a big change especially in election years. My query has a line chart as default view and uses the absolute numbers instead of percentages: Popperipopp, Jura1@
Use at
- https://query.wikidata.org/sparql
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/>
#defaultView:AreaChart
SELECT
?month
# (COUNT(DISTINCT ?m) as ?count_m)
# (COUNT(DISTINCT ?f) as ?count_f) (COUNT(DISTINCT ?item) as ?count_all)
( ROUND( COUNT(DISTINCT ?f) / COUNT(DISTINCT ?item) * 100) as ?pc_f)
WHERE
{
{
SELECT DISTINCT ?month { [] wdt:P31 wd:Q47018478 ; wdt:P585 ?month .
FILTER( YEAR(?month) > 1980 && YEAR(?month) < 2000 ) }
}
?pos ps:P39 wd:Q10655178 ; pq:P580 ?start .
OPTIONAL { ?pos pq:P582 ?end0 }
BIND( COALESCE( ?end0, NOW() ) as ?end)
FILTER( ?month >= ?start && ?month <= ?end )
?item p:P39 ?pos .
OPTIONAL { ?item wdt:P21 wd:Q6581072 . BIND(?item as ?f) }
# OPTIONAL { ?item wdt:P21 wd:Q6581097 . BIND(?item as ?m) }
}
GROUP BY ?month
ORDER BY ?month
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?end")
v5("?end0")
v7("?f")
v6("?item")
v1("?month"):::projected
v8("?pc_f")
v4("?pos")
v2("?start")
a1((" "))
c7(["wd:Q10655178"]):::iri
c4(["wd:Q47018478"]):::iri
c12(["wd:Q6581072"]):::iri
f0[["?month >= ?start?month <= ?end"]]
f0 --> v1
f0 --> v2
f0 --> v6
f1[["year-from-dateTime(?month) > '1980^^xsd:integer'year-from-dateTime(?month) < '2000^^xsd:integer'"]]
f1 --> v1
a1 --"p:direct/P31"--> c4
a1 --"p:direct/P585"--> v1
v4 --"p:statement/P39"--> c7
v4 --"p:qualifier/P580"--> v2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."p:qualifier/P582".-> v5
end
bind2[/"?end0NOW()"/]
v5 --o bind2
bind2 --as--o v6
v6 --"p:P39"--> v4
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:direct/P21".-> c12
bind3[/"?item"/]
v6 --o bind3
bind3 --as--o v7
end
bind6[/"numeric-round( / * '100^^xsd:integer')"/]
null --o bind6
null --o bind6
bind6 --as--o v8