Skip to main content
GROUP BY collapses your rows into groups and aggregates each metric within them. List one or more dimensions, separated by commas, and every metric in SHOW is totalled per group.
Grouping by two dimensions gives you a breakdown within a breakdown, such as product type within vendor.

Top N per dimension

Prefix a dimension with ONLY TOP <n> to keep just its highest-ranking values. This is handy on a two-dimension breakdown where you want, say, the top five vendors but every product type within them.
Which dimensions are available depends on the dataset. To filter groups by their totals after aggregating, use HAVING. To sort the grouped results, use ORDER BY.