At 19:41 +0200 5/5/04, Julien Martin wrote:
Hello,

Thanks a lot for the replies. I have changed the 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

GROUP BY
        ES.DB_ESTABLISHMENT_ID

HAVING
        AVG(DB_GRADE) > 2

ORDER BY
        AVG(GRADE)
**************************

Now I am having a problem with the order by clause. How can I have the AVG
function in the ORDER BY clause or how can I sort by average grade?

As others have noted, you can alias the column and refer to the alias in the ORDER BY clause, or refer to it by position in the SELECT list.

But I suspect the problem with the query above is that you refer
to the column as DB_GRADE in the SELECT list and HAVING clause, but
as GRADE in the ORDER 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]



Reply via email to