HAVING clause in SQL

HAVING clause is used to filter out records based on aggregated values. In the respect of aggregation, WHERE can’t be used. It does not work.

Therefore, while applying condition where we are calculating fields data, we will use HAVING.

See below example-

SELECT SUM(price) AS year_sale FROM mobiles GROUP BY year HAVING year_sale < 50000;

Leave a Comment