Error: An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
Description: This error occur when we try to use aggregate functions with WHERE clause. Because, WHERE clause filters ungrouped elements or we can say WHERE clause can filter only table row-by-row or individual records.
Solution: By using HAVING clause instead of WHERE clause, which specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement which should return only those rows where aggregate values meet the specified conditions. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.