Find all With sql query

Hi

SELECT DISTINCT( monthname( date_purchased ) ) AS month, month( date_purchased ) AS m FROM orders WHERE date_purchased LIKE ‘2010-%’ ORDER BY date_purchased DESC

I want above query with FindAll function how this possible ?

Any one help me

Thanks in advance.

Maybe:




$results=ModelName::model()->findAllBySql('SELECT DISTINCT( monthname( date_purchased ) ) AS month, month( date_purchased ) AS m FROM orders WHERE YEAR(date_purchased ) = 2010 ORDER BY date_purchased DESC');



and define $month and $m as attributes in your model so that these can be accessed when in loop:




foreach($results AS $result){

  echo $result->month;

  echo $result->m;

}



If i were you i would just use DAO:




$sql='SELECT DISTINCT( monthname( date_purchased ) ) AS month, month( date_purchased ) AS m FROM orders WHERE YEAR(date_purchased ) = 2010 ORDER BY date_purchased DESC';

$connection=Yii::app()->db;

$command=$connection->createCommand($sql)

$results=$command->queryAll(); 


foreach($results AS $result){

   echo $result['month'];

   echo $result['m'];

}



Hi

thanks for quick reply.

If i were you i would just use DAO: - this is working but not fist one.

Thanks