Data Operations and Support

Which SQL clause filters grouped results by SUM(revenue) in both Amazon Redshift and Athena?

Show the answer

Correct answerD. HAVING

AWhy not this: GROUP BY defines which rows contribute to each group; it does not apply an aggregate threshold.

BWhy not this: WHERE filters input rows before aggregation, rather than filtering aggregate results.

CWhy not this: ORDER BY sorts the result rows; it does not filter groups.

DWhy this is right: HAVING applies conditions to grouped results, including conditions on SUM(revenue).

HAVING filters groups using aggregate results such as SUM(revenue). WHERE filters individual input rows before grouping and cannot directly filter a grouped SUM.