由于在yii2 searchmodel中使用findbysql时搜索过滤不起作用,所以我想在Yii2中写一个等效的“SELECT * FROM challan WHERE id IN (SELECT MAX(id) FROM challan GROUP BY sid)
”查询
答案 0 :(得分:0)
$query->andWhere(new Expression('id IN (SELECT MAX(id) FROM challan GROUP BY sid)'));
答案 1 :(得分:0)
我花了很多时间后才找到答案,而这里是
Challan::find()->Where(['challan.id' => Challan::find()->select(['MAX(id)'])->groupBy('sid')]);