query-7f4d613976b459a4f8a5f18fc43811de

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
#title:P8034 by number of 20 most frequent occupations
#defaultView:BubbleChart
SELECT (SUM(?count) AS ?occ_count) (IF(?group=">20", " other", SAMPLE(?itemLabel)) AS ?occ)



WHERE
{
  hint:Query hint:optimizer "None".    
   {
        SELECT ?item (SUM(?x) AS ?rank) ?count WHERE {
           {  
        SELECT DISTINCT ?item (COUNT(?p) AS ?count) WHERE { ?p wdt:P8034 []; wdt:P106 ?item } GROUP BY ?item ORDER BY DESC(?count) 
      }.
           {
        SELECT (?item AS ?item2) (?count AS ?count2) WHERE { INCLUDE %all }
      }.
          BIND( IF( ?count  <= ?count2 , 1, 0 ) AS ?x ) .
        } GROUP BY ?item ?count
      }.
  BIND( IF(?rank < 21, STR(?rank), 
        ">20")
        AS ?group)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?item rdfs:label ?itemLabel }
}
GROUP BY ?group
ORDER BY (?group=">20") DESC(?occ_count)

Query found at