183k views
1 vote
HAVING: The HAVING clause further extends this by allowing us to specify a filter condition that each group must fulfil in order to be processed.

Option 1: WHERE
Option 2: HAVING
Option 3: GROUP BY
Option 4: ORDER BY

User Sejanus
by
7.9k points

1 Answer

2 votes

Final answer:

The correct option is 'Option 2: HAVING', which is used in SQL to filter groups after aggregation, in contrast to the 'WHERE' clause that filters before grouping, and the 'ORDER BY' clause that sorts results without filtering.

Step-by-step explanation:

The student's question pertains to a SQL clause that filters groups after an aggregation has been performed. The correct option to define this functionality is Option 2: HAVING. In SQL, the HAVING clause is often used in conjunction with the GROUP BY clause to apply a condition to the grouped rows, whereas the WHERE clause is used to filter rows before any grouping takes place. The ORDER BY clause is used to sort the result set in ascending or descending order, but it does not filter or group the results.

For example, if we have a table sales with columns region and amount, and we want to find regions with a total sales amount greater than $10,000, we would use the following query:

SELECT region, SUM(amount) AS total_sales
FROM sales
GROUP BY region
HAVING SUM(amount) > 10000;

This query groups the sales by region and filters out the groups that have a total sales amount greater than $10,000.

User Mahemoff
by
7.2k points