What is the purpose of the HAVING clause in Oracle?

In Oracle, the HAVING clause is used to filter data after the GROUP BY clause. It allows filtering the results of aggregate functions to only return data rows that meet the specified conditions.

The HAVING clause is typically used in conjunction with the GROUP BY clause to further filter the grouped data. It can contain aggregate functions (such as COUNT, SUM, AVG, etc.) and logical operators (such as AND, OR, NOT, etc.) in order to filter the results of the grouping based on specific conditions.

For example, if there is a table containing order data, we can group the data by customer using the GROUP BY clause, and filter out customers with more than 10 orders using the HAVING clause.

Show the customer IDs and number of orders for customers who have more than 10 orders.

This will return the customer_id and corresponding order quantity for customers with more than 10 orders.

bannerAds