Hi All,
I need help in writing below query in Yii.
I wanted to group by category with 5 records each.
Query which is working in MySql is as below, same need to be written in Yii, please help.
SELECT V.*,c.cnt FROM ne_posts V JOIN
( SELECT * FROM( SELECT cat_id,created_dt,COUNT(1) cnt FROM ne_posts GROUP BY cat_id )V
ORDER BY created_dt DESC LIMIT 5 )C
ON V.cat_id = C.cat_id
$criteria = new CDbCriteria();
$criteria->select = "*";
$criteria->addInCondition(‘status’, array(‘published’) );
$criteria->order = "t.created_dt DESC ";
$criteria->group = " t.cat_id ";
$posts = NePosts::model()->with(‘Cat’, ‘User’)->findAll($criteria);
Thanks in advanced.