Jamie Burns wrote:
>
> hi...
>
> i have a table as follows:
>
> ref smallint(5)
> product_ref smallint(5)
> rating smallint(1)
>
> is there any way i can get the average rating for each product_ref?
>
> for example...
>
> ref p_ref rating
> 1 1 4
> 2 1 5
> 3 1 3
> 4 1 5
> 5 2 4
> 6 2 5
> 7 3 3
> 8 3 2
>
> so that i could find out that:
>
> product_ref 1, has an average rating of 4.25
> product_ref 2, has an average rating of 4.5
> product_ref 3, has an average rating of 2.5
>
> and could i possibly return the 10 highest rows?
>
> any help with this would be really appreciated...
>
> jamie burns.
Hi,
>From MySQL documentation:
AVG(expr)
Returns the average value of expr:
mysql> select student_name, AVG(test_score)
from student
GROUP BY student_name;
Regards
--
Joseph Bueno
NetClub/Trader.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php