Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Using sum in CDbCriteria

$
0
0
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:

		$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.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>