Craig Hoffman wrote:
Mark,
Yes its close and thank you. The problem I am having is I am able to
generate the correct ranking.id for that particular user but I can't
seem to make it equal the ranking.rating.
ID ranking.rating
9 = 5.6 (example)
Here's my query:
SELECT routes.user_id, ran
Hi Craig,
Sorry this is such a slow response but I have been swamped and I didn't
see where anyone else has responded yet.
First, we need to calculate the average ID per user but round the average
to the nearest whole number.
CREATE TEMPORARY TABLE tmpResults
SELECT cast((AVG(id)+ .5) as inte
Mark,
Yes its close and thank you. The problem I am having is I am able to
generate the correct ranking.id for that particular user but I can't
seem to make it equal the ranking.rating.
ID ranking.rating
9 = 5.6 (example)
Here's my query:
SELECT routes.user_id, ranking.rating, ROUND(A
Hey Everyone,
I can you some assistance on this query.
I have three tables one is called ranking and the other is called
routes and finally the users table. The users table is not really
important.
The ranking table looks like this:
id rating
1 5.0
2 5.1
3 5.2
4 5.3
=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 h
Pretty simple, declare an alias in your query and use it in the ORDER BY, i.e.:
SELECT DB_ESTABLISHMENT_NAME, AVG(DB_GRADE) AS AVGGRADEFROM ESTABLISHMENTS ES LEFT OUTER JOIN GRADES GR ONES.DB_ESTABLISHMENT_ID=GR.DB_ESTABLISHMENT_IDGROUP BY ES.DB_ESTABLISHMENT_IDHAVING AVG(DB_GRADE) > 2ORDER B
ISHMENTS 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 wit
***
>
> 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?
I THINK you need to alias your column to do this:
SELECT
DB_ESTABLISHMENT_NAME,
AVG(DB_GRADE) AS AVG_GRADE
Thank you all for your replies. Everything works now!!
Julien.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
What kind of problem are you having? You can use the ordinal postion.
ORDER BY 2 [ASC|DESC]. 2 represents the second column.
-Original Message-
From: Julien Martin
To: '[EMAIL PROTECTED]'
Sent: 5/5/04 12:41 PM
Subject: AVG function in order by clause
Hello,
Thanks a lot for t
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?
Thanks in advance,
Julien Mar
11 matches
Mail list logo