Hello,
I have a sql query as follows:
************************** SELECT DB_ESTABLISHMENT_NAME, AVG(DB_GRADE)
FROM ESTABLISHMENTS ES LEFT OUTER JOIN GRADES GR ON ES.DB_ESTABLISHMENT_ID=GR.DB_ESTABLISHMENT_ID
WHERE AVG(DB_GRADE) > 2
GROUP BY ES.DB_ESTABLISHMENT_ID ; ************************** and I get the following error:
ERROR 1111: Invalid use of group function
Can anyone tell me how to use a function in the where clause?
No, because you can't use aggregate functions in the WHERE clause.
However, for the particular query you show above, you can put the condition in the HAVING clause, where you *can* use aggregate functions. (Change WHERE to HAVING and move the clause after the GROUP BY clause.)
-- Paul DuBois, MySQL Documentation Team Madison, Wisconsin, USA MySQL AB, www.mysql.com
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]