Reputation: 899
I try to execute a simple query like this:
$tot = Yii::app()->db->createCommand()
->select('sum(field)')
->from('products')
->where('id = ' . $id)
->queryRow();
But $tot return me null value.
Upvotes: 3
Views: 10069
Reputation: 4150
I think you need to add an alias to your sum, so something like this might work:
$tot = Yii::app()->db->createCommand()
->select('sum(field) as mySum')
->from('products')
->where('id = ' . $id)
->queryRow();
Upvotes: 6