I want to create my query with cdbcriteria in YII , with out using createCommand.
select count(*) count
from (select id,player_id,goals_scored,if(goals_scored>0,@counter:=@counter+1,@counter:=0) count from player_stats, (select @counter:=1) b
where player_id='1000099' and @counter>0 order by id desc) f
How can I create correct SQL query in YII syntax?
Why do you need CDbCriteria
for this? You probably need the DAO
and something like this:
$count = Yii::app()->db->createCommand("
select count(*) count
from (select id,player_id,goals_scored,if(goals_scored>0,@counter:=@counter+1,@counter:=0) count from player_stats, (select @counter:=1) b
where player_id='1000099' and @counter>0 order by id desc) f
")->queryScalar();
Usually CDbCriteria is used with ActiveRecord models but I don't see how it would be applicable in this particular case. If not, please show the full code sample.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.