query: SELECT ?grouping (SAMPLE(?_higher_grouping) as ?higher_grouping) (COUNT(DISTINCT ?entity) as ?count) (SAMPLE(?entity) as ?sample) WHERE { ?entity wdt:P1260 ?id. FILTER(REGEX(?id, "^raa/bbr(a|b|)/")). ?entity wdt:P131 ?grouping. OPTIONAL { ?grouping wdt:P131  ?_higher_grouping } } GROUP BY ?grouping HAVING (?count > 20) ORDER BY DESC(?count) LIMIT 1000