php - how to run a cumulative derived query in yii -


i have table 3 fields(id, jobsprocess,percent) , want work out cumulative percent on fly, derived field.

in sql this, returns 13 records.

set @x := 0; select id, jobsprocess, percent, (@x := @x + percent) cumaltive `hdb`.`lookupprocess` inner join jobsprocess on jobprocess = process_id projid = 1302035 order id 

how can in yii? far have following not giving me results want

$lastrun = yii::app()->db->createcommand("                     select id, jobsprocess, percent , (:criteria = :criteria + percent) cumulative                     `hdb`.`lookupprocess`                     inner join jobsprocess on jobprocess = process_id                     projid = $projid                     order id " )->queryall(true, array(':criteria'=>0)); 

returns 13 records cumulative 0.

i have tried th3e following error

$user = yii::app()->db->createcommand()     ->select('id, jobsprocess, percent , (:zero := (:zero + percent)) cumulative')     ->from('lookupprocess')     ->join('jobsprocess','jobprocess = process_id')     ->where('projid = :projid', array(':projid'=>$projid,':zero'=>0))      ->queryall(); 

it takes :zero string.

cdbcommand failed execute sql statement: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near ':= ('0' + percent)) cumulative `lookupprocess` join `jobsprocess` on job' @ line 1. sql statement executed was: select id, jobsprocess, percent , (:zero := (:zero + percent)) cumulative `lookupprocess` join `jobsprocess` on jobprocess = process_id projid = :projid  

you can declare sql variable in part of query:

select id, jobsprocess, percent, (@x := @x + percent) cumaltive `hdb`.`lookupprocess`, (select @x=0) q inner join jobsprocess on jobprocess = process_id projid = 1302035 order id 

so, this:

$lastrun = yii::app()->db->createcommand("     select id, jobsprocess, percent , (@x := @x + percent) cumulative     `hdb`.`lookupprocess`, (select @x:=0) q     inner join jobsprocess on jobprocess = process_id     projid = $projid     order id " )->queryall(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -