I have a rating table, I need to get the average rating for certain record. However , when I use AR method, it did not return the average which is what I need. All it returns are those attributes defined in the model file.
How can I get the average of certain fields? thanks
Page 1 of 1
how to sum up and avg data
#2
Posted 28 July 2009 - 02:31 AM
Answer on your question is statistical query described in Guide.
AFAIK you have to pass MAX(column_name) into select attribute if you want ot achieve max value, AVG(column_name) for average and so one...
AFAIK you have to pass MAX(column_name) into select attribute if you want ot achieve max value, AVG(column_name) for average and so one...
I'm not complete idiot... some parts are missing!
#3
Posted 28 July 2009 - 07:42 AM
I did read that part, however that is only for count . temporarily I used PDO to solve it. However, to keep code persistent, I still what to find out how. Could anybody give me an example? Thanks
#5
Posted 01 August 2009 - 09:53 PM
I tried to use findBySql('select avg(rating) from ...), however the returned object doesn't have the average value, even if I use
"select avg() as average", still nothing got returned when I print_r the returned object.
Do I need to define a property in the model for average value? I don't understand your explaination
thanks
"select avg() as average", still nothing got returned when I print_r the returned object.
Do I need to define a property in the model for average value? I don't understand your explaination
thanks
#6
Posted 29 November 2011 - 11:58 AM
Irecommend you to add the following to the rules in your model :
It should be really easy to do it like this.
'average' => array(self::STAT, 'ModelRelated', 'ColumnRelated',
'select' => 'AVG(FIELD)',
'select' => 'AVG(FIELD)',
It should be really easy to do it like this.
--
MSc. Cristian Tala Sánchez
MSc. Cristian Tala Sánchez
Share this topic:
Page 1 of 1

Help

This topic is locked










