query: SELECT ?grouping (SAMPLE(?_higher_grouping) as ?higher_grouping) (COUNT(DISTINCT ?entity) as ?count) (SAMPLE(?entity) as ?sample) WHERE { ?entity wdt:P882 []; wdt:P17 wd:Q30. ?entity wdt:P31 ?grouping. OPTIONAL { ?grouping wdt:P1001  ?_higher_grouping } } GROUP BY ?grouping HAVING (?count > 0) ORDER BY DESC(?count) LIMIT 1000