query-0b03b840059127051b7cf6d913c3c7af
Computing the share of males, females and non binary peopleThis query compute share of women, men, intersexual and non-binary people in the article "Economics". I group together "transgender male" with "male" and "transgender female" with "female". Caveat : the ROUND function rounds to unity and not to decimal.
Use at
- https://query.wikidata.org/sparql
PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT
(SUM(?female) AS ?count_females)
(SUM(?male) AS ?count_males)
(SUM(?nonbinary) AS ?count_nonbinary)
(SUM(?intersexual) AS ?count_intersexual)
(COUNT(*) AS ?count)
(ROUND(100 * ?count_females / ?count) AS ?share_females)
(ROUND(100 * ?count_males / ?count) AS ?share_males)
(ROUND(100 * ?count_nonbinary / ?count) AS ?share_nonbinary)
(ROUND(100 * ?count_intersexual / ?count) AS ?share_intersexual)
{
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "en.wikipedia.org";
wikibase:api "Generator";
mwapi:generator "links";
mwapi:titles "Economics";.
?item wikibase:apiOutputItem mwapi:item.
}
FILTER BOUND (?item)
?item wdt:P31 wd:Q5 .
?item wdt:P21 ?gender .
BIND(IF(?gender IN(wd:Q6581097, wd:Q2449503), 1, 0) AS ?male )
BIND(IF(?gender IN(wd:Q6581072, wd:Q1052281), 1, 0 ) AS ?female)
BIND(IF(?gender = wd:Q48270, 1, 0) AS ?nonbinary)
BIND(IF(?gender = wd:Q1097630, 1,0) AS ?intersexual)
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v11("?count"):::projected
v7("?count_females"):::projected
v10("?count_intersexual"):::projected
v8("?count_males"):::projected
v9("?count_nonbinary"):::projected
v4("?female"):::projected
v2("?gender")
v6("?intersexual"):::projected
v1("?item")
v3("?male"):::projected
v5("?nonbinary"):::projected
v12("?share_females")
v15("?share_intersexual")
v13("?share_males")
v14("?share_nonbinary")
c10(["Economics"]):::literal
c12(["mwapi:item"]):::iri
c4(["en.wikipedia.org"]):::literal
c2(["bd:serviceParam"]):::iri
c14(["wd:Q5"]):::iri
c8(["links"]):::literal
c6(["Generator"]):::literal
f0[["bound(?item)"]]
f0 --> v1
subgraph s1["http://wikiba.se/ontology#mwapi"]
style s1 stroke-width:4px;
c2 --"mwapi:endpoint"--> c4
c2 --"mwapi:api"--> c6
c2 --"mwapi:generator"--> c8
c2 --"mwapi:titles"--> c10
v1 --"mwapi:apiOutputItem"--> c12
end
v1 --"wdt:P31"--> c14
v1 --"wdt:P21"--> v2
list0c2(["wd:Q2449503"]):::iri
list0c1(["wd:Q6581097"]):::iri
list0c1 --o bind1
list0c2 --o bind1
bind1[/"if( in ,'1^^xsd:integer','0^^xsd:integer')"/]
v2 --o bind1
bind1 --as--o v3
list1c2(["wd:Q1052281"]):::iri
list1c1(["wd:Q6581072"]):::iri
list1c1 --o bind2
list1c2 --o bind2
bind2[/"if( in ,'1^^xsd:integer','0^^xsd:integer')"/]
v2 --o bind2
bind2 --as--o v4
bind3[/"if(?gender = 'wd:Q48270','1^^xsd:integer','0^^xsd:integer')"/]
v2 --o bind3
bind3 --as--o v5
bind4[/"if(?gender = 'wd:Q1097630','1^^xsd:integer','0^^xsd:integer')"/]
v2 --o bind4
bind4 --as--o v6
bind10[/"sum(?female)"/]
v4 --o bind10
bind10 --as--o v7
bind11[/"sum(?male)"/]
v3 --o bind11
bind11 --as--o v8
bind12[/"sum(?nonbinary)"/]
v5 --o bind12
bind12 --as--o v9
bind13[/"sum(?intersexual)"/]
v6 --o bind13
bind13 --as--o v10
bind14[/"count(*)"/]
bind14 --as--o v11
bind15[/"numeric-round('100^^xsd:integer' * ?count_females / ?count)"/]
v7 --o bind15
v11 --o bind15
bind15 --as--o v12
bind16[/"numeric-round('100^^xsd:integer' * ?count_males / ?count)"/]
v8 --o bind16
v11 --o bind16
bind16 --as--o v13
bind17[/"numeric-round('100^^xsd:integer' * ?count_nonbinary / ?count)"/]
v9 --o bind17
v11 --o bind17
bind17 --as--o v14
bind18[/"numeric-round('100^^xsd:integer' * ?count_intersexual / ?count)"/]
v10 --o bind18
v11 --o bind18
bind18 --as--o v15