HAVING Clause
The HAVING clause lets you filter groups after aggregation has been applied.
It works like WHERE, but specifically filters the results of grouped data.
Basic Syntax
The HAVING clause comes after GROUP BY in a SELECT statement.
HAVING Syntax
SELECT column, AGG_FUNCTION(column) FROM table_name GROUP BY column HAVING condition;
Example: Regions with High Sales
Suppose you have a clients table and want to find regions where total sales exceed 25,000.
Use the HAVING clause to filter results after grouping.
Regions with high sales
SELECT region, SUM(sales) AS total_sales FROM clients GROUP BY region HAVING SUM(sales) > 25000;
Quiz
0 / 1
The HAVING clause in SQL is used to filter rows before they are grouped.
True
False
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Tables
Execution Result