Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in Yii's criteria how to get count (*)

Tags:

sql

php

yii

I'm trying to build a query that has a group by attribute, im truing to get the id and the count it keeps telling me that the count (*) is invalid column name how could i get the count from the group by query ??

like image 698
Hilmi Avatar asked May 02 '12 07:05

Hilmi


2 Answers

Work's with alias. Yii 1.1.11. Fails other

$criteria= new CDbCriteria();
$criteria=array(
            'group'=>'attribute',
            'select'=>'id,count(*) AS cc'
);
like image 78
duukkis Avatar answered Nov 13 '22 15:11

duukkis


This not exactly an answer to your question, but could still be useful for you. If you use the result to only look up one count for one specific attribute, you don't need to fecth an entire array, but use Yii's count method:

$criteria= new CDbCriteria();
$criteria.compare('col_name', $desired_col_value);
$count = X::model()->count($criteria);
like image 5
physicalattraction Avatar answered Nov 13 '22 14:11

physicalattraction