How To Write A Customised Query To Fetch Result Array An Display

following is my query how do i place what code in view ,model,controller in yii

select productid, count(*)

from fc_member

group by productid

order by count(*)desc


Please let me know i am a newbie

i did try but then do not the how and what of it :(

You could try with createCommand method:

$result= Yii::app()->db->createCommand()

                ->select('productid, COUNT(*) as count')


                ->group('productid ')



thankx master Q

the thing is i have to display the result in gridview

in view displayproducts


    $this->widget('zii.widgets.grid.CGridView', array(

        'id' => 'detail-grid',

        'dataProvider' => $dataProvider,

        'filter' => $dataProvider,

        'columns' => array(





in controller actiondisplayproduct

/*the Controller*/

$dataProvider=new CActiveDataProvider('$model',



                                                        'select'=>'productid, count(*) as count',



                                                        'order'=>'count(*) Desc LIMIT 3', 








but then i its not working out :(