简体   繁体   中英

$criteria->select in yii

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.

try this

$criteria->select = array('rate', 'avg(rate) as avgRate');

And don't forget to define $avgRate as a public variable in your model.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM