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

LIMIT 3

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')

                ->from('fc_member')

                ->group('productid ')

                ->limit(3)

                ->queryAll();



thankx master Q

the thing is i have to display the result in gridview

in view displayproducts




<?php

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

        'id' => 'detail-grid',

        'dataProvider' => $dataProvider,

        'filter' => $dataProvider,

        'columns' => array(

            

'productid',

'count',

            ),));








in controller actiondisplayproduct


/*the Controller*/

$dataProvider=new CActiveDataProvider('$model',

                                array(

                                                'criteria'=>array(

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

                                                        'from'=>'fc_members',

                                                        'group'=>'productid',

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

                                                                                    

                                                ),

                                        )

                        );

                $this->render('displayproduct',array(

                        'dataProvider'=>$dataProvider,

                ));




but then i its not working out :(