Skip to main content
Version: 1.2

HAVING

WHERE filters input rows before grouping. HAVING filters grouped or aggregated results after grouping.

Examples

Find days where the average CPU utilization exceeded 80%:

SELECT
date_trunc('day', ts) AS day,
AVG(cpu_util) AS avg_cpu_util
FROM
system_metrics
GROUP BY
day
HAVING
avg_cpu_util > 80;

Find hours where the number of error logs is greater than 100:

SELECT
DATE_TRUNC('hour', log_time) AS hour,
COUNT(*) AS error_count
FROM
application_logs
WHERE
log_level = 'ERROR'
GROUP BY
hour
HAVING
error_count > 100;