> ## Documentation Index
> Fetch the complete documentation index at: https://docs.queryful.app/llms.txt
> Use this file to discover all available pages before exploring further.

# GROUP BY

> Break the results down by one or more dimensions.

`GROUP BY` splits the results into groups and totals each metric within them. List one or more dimensions, separated by commas.

```sql theme={null}
FROM sales
  SHOW net_sales, orders
  GROUP BY sales_channel
```

Two dimensions give a breakdown within a breakdown, such as product type within vendor:

```sql theme={null}
FROM sales
  SHOW net_sales
  GROUP BY product_vendor, product_type
```

## Over time

Group by `day`, `week` or `month` to split the results over time, the same as [TIMESERIES](https://docs.queryful.app/queryfulql/syntax/timeseries.md). It can sit alongside other dimensions:

```sql theme={null}
FROM sales
  SHOW net_sales
  GROUP BY month, sales_channel
  DURING this_year
```

For patterns within a week or a day, group by `day_of_week` or `hour_of_day`.

## Top values

`TOP n` before a dimension keeps its n highest values, ranked by the first metric (or the one in `ORDER BY`), and puts the rest together in an "Other" row. `ONLY TOP n` leaves the rest out instead.

```sql theme={null}
FROM sales
  SHOW net_sales
  GROUP BY ONLY TOP 5 product_vendor, product_type
```

On the second of two dimensions, the top values are picked within each value of the first: the top 3 products for each vendor. Add `OVERALL` after the dimension to pick the top values across the whole report instead.

```sql theme={null}
FROM sales
  SHOW net_sales
  GROUP BY product_vendor, TOP 3 product_title OVERALL
```

To keep only the groups whose totals match a condition, use [HAVING](https://docs.queryful.app/queryfulql/syntax/having.md). To sort them, use [ORDER BY](https://docs.queryful.app/queryfulql/syntax/order-by.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.