我已经实现了 mysql 查询并且工作正常,但是在 Yii2 中转换/实现它时,我在使用 active record 时遇到了一些困难。
SELECT
COUNT(price) AS total,
SUM(IF(is_veg = 'Y', 1, 0)) AS veg_count,
SUM(IF(is_not_veg = 'Y', 1, 0)) AS non_veg_count
FROM order_table
我试过做以下
orderTable::find()
->select('count(price) as total')
->sum(new Expression("IF(is_veg = 'Y', 1, 0)") => 'veg_count')
->sum(new Expression("IF(is_not_veg = 'Y', 1, 0)") => 'non_veg_count');
我收到以下错误:语法错误,意外的 '=>' (T_DOUBLE_ARROW),期待 ',' 或 ')'
守候你守候我