有人可以幫我把下面的代碼轉換成Yii查詢嗎?我會liek它返回款型的陣列派生列如何將PDO查詢轉換爲Yii查詢?
$sql = 'UPDATE jobs
RIGHT JOIN (
SELECT jobs.JOBNO,
round(details' . $type['type'] . '.' . $type['km'] . ' * sum(PRICE),2) AS JOBSVALUE
FROM jobs
JOIN projects ON jobs.PROJID = projects.PROJID
JOIN biditems ON projects.id = biditems.project_id
JOIN details' . $type['type'] . ' on jobs.JOBNO = details' . $type['type'] . '.JOBNO
WHERE jobs.PROJID = :pid
GROUP BY jobs.JOBNO
) AS temp ON jobs.JOBNO = temp.JOBNO
SET jobs.VALUE = JOBSVALUE';
$command=$connection->createCommand($sql);
$command->bindValue(":pid", $model->PROJID,PDO::PARAM_INT);
$command->execute();
$sql = "UPDATE jobs j
JOIN (
SELECT j.JOBNO, COUNT(l.JOBNO) AS numlis
FROM lineitems l
RIGHT JOIN jobs j ON j.JOBNO = l.JOBNO
WHERE j.PROJID = :pid
GROUP BY j.JOBNO
) t ON j.JOBNO = t.JOBNO
SET `VALUE` = 0, `EARNED` = 0
WHERE PROJID = :pid AND t.numlis = 0;";
$command=$connection->createCommand($sql);
$command->bindValue(":pid", $model->PROJID,PDO::PARAM_INT);
$command->execute();
1日嘗試
$sql = "select jobs.JOBNO, round(details".$type['type'].".".$type['km']." * sum(PRICE),2) AS JOBSVALUE
from jobs
join projects on jobs.PROJID = projects.PROJID
join biditems on projects.id = biditems.project_id
join details".$type['type']." on jobs.JOBNO = details".$type['type'].".JOBNO
where jobs.PROJID = :pid
GROUP BY jobs.JOBNO";
$command=$connection->createCommand($sql);
$command->bindValue(":pid",$model->PROJID,PDO::PARAM_INT);
$result = $command->queryAll();
foreach ($result as $value) {
$job = Jobs::model()->findByPk($value['JOBNO']);
$job->VALUE = $value['JOBSVALUE'];
$job->save();
}
$sql = "SELECT j.JOBNO, COUNT(l.JOBNO) AS numlis
FROM lineitems l
RIGHT JOIN jobs j ON j.JOBNO = l.JOBNO
WHERE j.PROJID = :pid
GROUP BY j.JOBNO";
$command=$connection->createCommand($sql);
$command->bindValue(":pid",$model->PROJID,PDO::PARAM_INT);
$result = $command->queryAll();
foreach ($result as $value) {
if($value['numlis'] == 0){
$job = Jobs::model()->findByPk($value['JOBNO']);
$job->VALUE = 0;
$job->EARNED = 0;
$job->save();
}
}
查看http://www.yiiframework .com/doc/api/1.1/CDbCommand – Dinistro
您會首先添加您的嘗試嗎?人們會提供幫助,但前提是他們看到事先的努力。 – halfer
@halfer更新 – shorif2000