在AC中,此顺序效果很好,但“查询”构建器的引号错误,结果错误
$models = Yii::app()->db->createCommand()
->select('id, user_id, title, created, modified, lang, forum_id, post_id, status, views, replies, attached')
->from('posts')
->where('post_id = 0')
->order('attached AND forum_id = 1 AND created DESC, created DESC')
->limit(11)
->queryAll();
错误:
CDbCommandнеудалосьисполнитьSQL-запрос:SQLSTATE [42S22]:未找到列:1054未知列'附加AND forum_id = 1并且'在'order子句'中创建'。执行的SQL语句是:SELECT
id
,user_id
,title
,created
,modified
,lang
,forum_id
,{ {1}},post_id
,status
,views
,replies
来自attached
WHERE post_id = 0 ORDER BYposts
DESC,attached AND forum_id = 1 AND created
DESC,replies
DESC LIMIT 11
如何解决?
P.S。抱歉我的英文。
答案 0 :(得分:2)
您的where
和order
应该是:
->where('post_id = 0')
->order('CASE WHEN forum_id =1 THEN 1 ELSE 2 END, created DESC')
答案 1 :(得分:0)
您应该在圆括号中使用顺序表达式以避免检查列。这必须工作
->order('(attached AND forum_id = 1 AND created) DESC, created DESC')