An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, ...