HAVING
HAVING filters the grouped rows by a number you show. Use it for questions like “owners with at least 3 won deals”.
FROM dealsSHOW won_count, won_valueGROUP BY ownerHAVING won_count >= 3Syntax
Section titled “Syntax”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.
Examples
Section titled “Examples”-- Industries where the average account is bigFROM accountsSHOW avg(annual_revenue), countGROUP BY industryHAVING avg(annual_revenue) > 100000-- Sources with many contacts or a high win rateFROM contactsSHOW count, deals.won_count * 100 / deals.count AS win_pctGROUP BY sourceHAVING count >= 50 OR win_pct > 30