SELECT
(?number_of_persons / ?total AS ?fraction)
?occupation ?occupationLabel ?occupationDescription
WITH {
SELECT
?person
WHERE {
?person wdt:P496 [] .
}
LIMIT 10000
} AS %persons
WITH {
SELECT
(COUNT(?person) AS ?number_of_persons)
?occupation
WHERE {
INCLUDE %persons
?person wdt:P106 ?occupation .
}
GROUP BY ?occupation
} AS %counts
WITH {
SELECT
(SUM(?number_of_persons) AS ?total)
WHERE {
INCLUDE %counts
BIND(1 AS ?dummy)
}
GROUP BY ?dummy
} AS %total
WHERE {
INCLUDE %counts
INCLUDE %total
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?number_of_persons)