I need to sum a column as I pull it out of a database. My sql query works fine and is as follows:
SELECT User.userName, sum(views) FROM Rant LEFT JOIN User ON Rant.userId = User.userId GROUP BY User.userId ORDER BY views DESC LIMIT 5;
My CDbCriteria is as follows:
I'm getting the following error when I try to loop through the data in my view:
record "Rant" is trying to select an invalid column "sum(views)". Note, the column must exist in the table or be an expression with alias.
SELECT User.userName, sum(views) FROM Rant LEFT JOIN User ON Rant.userId = User.userId GROUP BY User.userId ORDER BY views DESC LIMIT 5;
My CDbCriteria is as follows:
$criteria=new CDbCriteria; $criteria->select = 'sum(views), userName'; $criteria->with = 'user'; $criteria->order='views DESC'; $criteria->group = 'user.userId'; $criteria->limit=5; $dataProvider3=new CActiveDataProvider('Rant', array( 'criteria'=>$criteria, ));
I'm getting the following error when I try to loop through the data in my view:
record "Rant" is trying to select an invalid column "sum(views)". Note, the column must exist in the table or be an expression with alias.