yii 使用原生sql 查询 以某一字段分组 每个字段取出最新的一条数据

时间:2021-10-25 19:19:07
$sql = "SELECT * FROM `l_company_distributor_message` WHERE id IN (SELECT MAX(id) FROM `l_company_distributor_message` WHERE distributor_id = ".$this->_distributorId."  GROUP BY company_id )";
$message = Yii::$app->getDb()->createCommand($sql)->queryAll();