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

# HAVING

> Filter groups by their aggregated metrics, after grouping

`HAVING` filters the grouped results by their totals. Where [WHERE](/stockfulql/syntax/where) runs before grouping and looks at individual rows, `HAVING` runs after grouping and looks at each group's aggregated metrics.

```sql theme={null}
FROM sales
  SHOW total_revenue, units_sold
  GROUP BY vendor
  HAVING total_revenue > 1000
```

This keeps only the vendors whose total revenue tops 1,000. `HAVING` uses the same operators and `AND` / `OR` logic as `WHERE`, so you can combine conditions.

```sql theme={null}
FROM sales
  SHOW total_revenue, units_sold
  GROUP BY vendor
  HAVING total_revenue > 1000 AND units_sold > 50
```

Because it acts on group totals, `HAVING` needs a [GROUP BY](/stockfulql/syntax/group-by). To cap how many groups you keep once they are filtered and sorted, add [ORDER BY](/stockfulql/syntax/order-by) and [LIMIT](/stockfulql/syntax/limit).
