query-251d0b152b83c7c7a5536c65447931d9

rq turtle/ttl

: One solution : Jane023, Spinster@One other to include the number of unknown gender :

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
select (count(?male)/count(?item) * 100 as ?percentman) (count(?female)/count(?item) * 100 as ?percentwoman) (count(?other)/count(?item) * 100 as ?percentother) (count(?other)/count(?item) * 100 as ?percentunknown) where { 
    ################################################################################
    # this part defines the dataset you want to query, put whatever you want in it
    # example:
    #?item wdt:P31 wd:Q5 .
    #but this could be
     {
     select ?item where {
       ?item wdt:P31 wd:Q5 .
     } limit 250000  }
    ################################################################################

    optional { bind("1" as ?male) . ?item wdt:P21 wd:Q6581097 .}
    optional { bind("1" as ?female) . ?item wdt:P21 wd:Q6581072 . }
    optional { bind("1" as ?other) . ?item wdt:P21 ?gender filter (?gender not in (wd:Q6581097, wd:Q6581072) ). }
    optional { bind("1" as ?unknown) . ?item wdt:P21 ?gender filter (!bound(?gender)). }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?female") v1("?gender") v2("?item") v3("?male") v5("?other") v7("?percentman") v9("?percentother") v10("?percentunknown") v8("?percentwoman") v6("?unknown") c1(["wd:Q6581097"]):::iri c4(["wd:Q5"]):::iri c2(["wd:Q6581072"]):::iri v2 --"wdt:P31"--> c4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; bind0[/"'1'"/] bind0 --as--o v3 v2 -."wdt:P21".-> c1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; bind1[/"'1'"/] bind1 --as--o v4 v2 -."wdt:P21".-> c2 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; bind2[/"'1'"/] bind2 --as--o v5 v2 -."wdt:P21".-> v1 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; bind3[/"'1'"/] bind3 --as--o v6 v2 -."wdt:P21".-> v1 end bind12[/" / * '100^^xsd:integer'"/] null --o bind12 null --o bind12 bind12 --as--o v7 bind13[/" / * '100^^xsd:integer'"/] null --o bind13 null --o bind13 bind13 --as--o v8 bind14[/" / * '100^^xsd:integer'"/] null --o bind14 null --o bind14 bind14 --as--o v9 bind15[/" / * '100^^xsd:integer'"/] null --o bind15 null --o bind15 bind15 --as--o v10