SQL Flow Field Guide

SELECT - HAVING

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

post-aggregation filter

What changes

Input
groups and aggregate values from GROUP BY
Output or change
groups that satisfy the condition

Syntax at a glance

[ HAVING <search condition> ]

Work example

A grouped report should keep only regions whose total reaches a threshold.

Run the sample, then change the threshold. Put row filters in WHERE and aggregate filters in HAVING.

Check your work SELECT - HAVING. Only North remains at a threshold of 20. South is removed after grouping.

Practice SQL

Open in SQL Flow
SELECT Region, SUM(Amount) AS Total
FROM (VALUES (N'North', 10), (N'North', 15), (N'South', 8)) AS Sales(Region, Amount)
GROUP BY Region
HAVING SUM(Amount) >= 20;

Open Microsoft Learn for full syntax, permissions, and details for your version.