Skip to content

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

FROM deals
SHOW won_count, won_value
GROUP BY owner
HAVING won_count >= 3
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 condition.

-- Industries where the average account is big
FROM accounts
SHOW avg(annual_revenue), count
GROUP BY industry
HAVING avg(annual_revenue) > 100000
-- 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