1

在我的模型中,我写道:

$criteria->select =  ' ( select avg( IfNULL( TR.stars_rating_type_id , 0) ) as stars_rating_type_id from '.$tablePrefix.'tour_review as TR where TR.tour_id = T.id and TR.status = \'A\' ) as reviews_avg_rating ';

我得到错误:

活动记录“Tour”正在尝试选择无效列“( select avg( IfNULL( TR.stars_rating_type_id”。注意,该列必须存在于表中或者是具有别名的表达式。

The reason is that I add "IfNULL( ..., 0)" function in subquery to escape "null" in result set.

没有它,我必须进行额外的验证并在 null 的情况下设置 0。

如果我用它测试原始 sql" SELECT ( select avg( IfNULL( TR.stars_rating_type_id, 0) ) as stars_rating_type_id..."可以正常工作,那么这就是 yii 方面的问题。如何解决?

Yii 1.1.14
谢谢!

4

1 回答 1

0

看一下手册:

http://www.yiiframework.com/doc/api/1.1/CDbCriteria

选择参数接收将要搜索的列,而不是孔查询

于 2014-06-02T14:36:09.040 回答