使用这样的查询:
原文链接:https://www.f2er.com/php/133563.htmlSELECT * FROM ( SELECT * FROM message ORDER BY added_on DESC ) as m WHERE receiver_id = 2 GROUP BY sender_id ORDER BY priority_id DESC;
我知道如何使用findAllBysql来做到这一点:
$this->findAllBysql( 'SELECT * FROM ( SELECT * FROM message ORDER BY added_on DESC ) as m WHERE receiver_id = :receiverId GROUP BY sender_id ORDER BY priority_id DESC',array('receiverId' => $userId));
但是我想知道是否有任何方法可以使用CDbCriteria执行此操作,因为以下代码当然不起作用:
$criteria = new CDbCriteria(); $criteria->condition = 'receiver_id = :receiverId'; $criteria->group = 'sender_id'; $criteria->order = 'priority_id DESC,added_on DESC'; $criteria->params = array('receiverId' => $userId);
谢谢.