Reputation: 1259
Is it possible to do the following in yii
$criteria=new CDbCriteria;
$criteria->select='avg(rate) as avgRate,rate';
I executed the following code but its returning the value for the column "rate" but not "avgRate" I know this could be done by createcommand but I want to use CDbCriteria.
Upvotes: 3
Views: 25313
Reputation: 6668
try this
$criteria->select = array('rate', 'avg(rate) as avgRate');
And don't forget to define $avgRate
as a public variable in your model.
Upvotes: 8
Reputation: 9402
You should be able to do this, but you will have to define $avgRate property in your model assuming you are using it that way.
Also, I'm not sure if your example is literally what you want to do as the "rate" value won't have much use.
Upvotes: 2