T
T
tigra2016-02-05 14:40:52
Yii
tigra, 2016-02-05 14:40:52

How to properly build a YII query?

There is a simple request

$criteria = new CDbCriteria();
$criteria->group = 't.project_id';
return $this->findAll($criteria);

but I also need to calculate the average of one field in this query
$criteria->select = new CDbExpression('*, AVG(optimisation)');

I tried this, it doesn't work,
in fact, you need to execute this query
SELECT *, AVG(`optimization`) FROM `table` ORDER BY `project_id`

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery, 2016-02-05
@tigroid3

Maybe so?
$criteria->select = array( '*', new CDbExpression('AVG(optimisation)') );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question