query-0a10fcb27d98ccbb01671df8e0e41a17

rq turtle/ttl

Hiperterminal

Use at

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 ?occupation ?occupationLabel ?count ?males ?females
WHERE
{

{
  SELECT ?occupation (COUNT(?item) AS ?count) (SUM(?male) AS ?males) (SUM(?female) AS ?females)
  WHERE
  {
    ?item wdt:P31 wd:Q5. # item is human
    ?item wdt:P106 ?occupation.
    ?occupation wdt:P279* wd:Q901. # occupation is subclass of scientist
    OPTIONAL { ?item wdt:P570 ?date_of_death. }
    FILTER (! BOUND(?date_of_death)) # No date of death meaning only living people
    OPTIONAL { ?item wdt:P21 ?gender. }
    BIND (IF (?gender = wd:Q6581097, 1, 0) AS ?male)
    BIND (IF (?gender = wd:Q6581072, 1, 0) AS ?female)
  }
  GROUP BY ?occupation
}  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?count"):::projected v1("?date_of_death") v6("?female") v9("?females"):::projected v4("?gender") v2("?item") v5("?male") v8("?males"):::projected v3("?occupation"):::projected c9(["bd:serviceParam"]):::iri c5(["wd:Q901"]):::iri c2(["wd:Q5"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["not bound(?date_of_death)"]] f0 --> v1 v2 --"wdt:P31"--> c2 v2 --"wdt:P106"--> v3 v3 --"wdt:P279"--> c5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P570".-> v1 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P21".-> v4 end bind1[/"if(?gender = 'wd:Q6581097','1^^xsd:integer','0^^xsd:integer')"/] v4 --o bind1 bind1 --as--o v5 bind2[/"if(?gender = 'wd:Q6581072','1^^xsd:integer','0^^xsd:integer')"/] v4 --o bind2 bind2 --as--o v6 bind6[/"count(?item)"/] v2 --o bind6 bind6 --as--o v7 bind7[/"sum(?male)"/] v5 --o bind7 bind7 --as--o v8 bind8[/"sum(?female)"/] v6 --o bind8 bind8 --as--o v9 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end