Seaquel
SQL Server error code

SQL Server error 147

SQL Server raises error 147 at severity 15, which marks a problem with the query or data that you can correct.

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.
Msg147
Severity15
Group0–999

How to fix it

In other databases

Source: Database Engine events and errors