Yii 2.0 的 group by 如何使用 case when? [ 2.0 版本 ]
YII2.0的group by如何使用case when?
我这样写为什么一直报错呢?
$articleList = $query->select($type)
->limit($pageSize)
->offset(($page - 1) * $pageSize)
->orderBy(
[
'case when al_id = 759 then 0 else 1 end' => SORT_DESC, //编号排序倒序
'al_post_time' => SORT_DESC, //编号排序倒序
]
)
->All();
Database Exception – yii\db\Exception
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'case when al_id = 759 then 0 else 1 end' in 'order clause'
The SQL being executed was: SELECT `al_id`, `al_title`, `al_desc`, `al_thumb`, `al_comment_num`, `al_collect_num`, `al_like_num`, `al_click_num`, `al_post_time`, `al_add_user_id`, `al_type`, `activity_id`, `al_is_hot_article` FROM `aaa` WHERE (`al_type` <> 1) AND (`al_status`=1) ORDER BY `case when al_id = 759 then 0 else 1 end` DESC, `al_post_time` DESC LIMIT 20
Error Info: Array
(
[0] => 42S22
[1] => 1054
[2] => Unknown column 'case when al_id = 759 then 0 else 1 end' in 'order clause'
)
↵
Caused by: PDOException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'case when al_id = 759 then 0 else 1 end' in 'order clause'
in D:\root\PHPTutorial\WWW\ewaasa\vendor\yiisoft\yii2\db\Command.php at line 915
共 2 个回答
PHP学院的中学生
注册时间:2018-10-23
最后登录:2024-09-23
在线时长:168小时13分
最后登录:2024-09-23
在线时长:168小时13分
- 粉丝29
- 金钱4725
- 威望30
- 积分6705