# HAVING

> Keep only the groups whose numbers match, after grouping.

`HAVING` filters the grouped rows by a number you show. Use it for questions like "owners with at least 3 won deals".

```sql
FROM deals
SHOW won_count, won_value
GROUP BY owner
HAVING won_count >= 3
```

## Syntax

```sql
HAVING <condition> [AND | OR <condition> ...]
```

A condition compares a shown metric (or its `AS` name, or a function such as `sum(amount)`) with a number:

| Condition | Example |
|---|---|
| Compare | `count > 5`, `>=`, `<`, `<=`, `=`, `!=` |
| Between | `value BETWEEN 1000 AND 5000`, `NOT BETWEEN` |
| One of | `count IN (1, 2)`, `NOT IN` |
| Empty | `avg_won IS NULL` |

Join conditions with `AND` and `OR`, and group them with parentheses. A condition on a field you group by works too, and acts like a [WHERE](https://workstation.repzo.com/docs/analytics/repzoql/where) condition.

## Examples

```sql
-- Industries where the average account is big
FROM accounts
SHOW avg(annual_revenue), count
GROUP BY industry
HAVING avg(annual_revenue) > 100000
```

```sql
-- Sources with many contacts or a high win rate
FROM contacts
SHOW count, deals.won_count * 100 / deals.count AS win_pct
GROUP BY source
HAVING count >= 50 OR win_pct > 30
```

## Related pages

- [WHERE](https://workstation.repzo.com/docs/analytics/repzoql/where)
- [GROUP BY](https://workstation.repzo.com/docs/analytics/repzoql/group-by)
