我有以下查询,它不返回任何行。但是,如果发生这种情况,我想将值设置为 0 或 null。我该怎么做呢?
UPDATE `hdb`.`projects`
RIGHT JOIN (
SELECT jobs.PROJID, round(SUM(jobs.value),2) AS SumOfJobValues, round(Sum(jobs.Earned),2) AS SumOfEarnedValues
FROM jobs
WHERE projects.PROJID = 1312184
GROUP BY jobs.PROJID
) as temp ON projects.PROJID = temp.PROJID
SET
projects.VALUE = round(SumOfJobValues,2),
projects.WIP = round(SumOfEarnedValues,2)
我重写了使用左连接的查询,它在 mysql 中工作。但是,当我使用 php Yii 框架运行它时,我无法正常工作。
UPDATE `hdb`.`projects`
left JOIN (
SELECT
jobs.PROJID,
round(SUM(jobs.value),2) AS SumOfJobValues,
round(Sum(jobs.Earned),2) AS SumOfEarnedValues
FROM jobs
GROUP BY jobs.PROJID
) as temp ON projects.PROJID = temp.PROJID
SET
projects.VALUE = round(SumOfJobValues,2),
projects.WIP = round(SumOfEarnedValues,2)
WHERE projects.PROJID = 1312184
在 php Yii 上运行相同的查询
$sql = "UPDATE `hdb`.`projects`
LEFT JOIN (
SELECT
jobs.PROJID, round(SUM(jobs.value),2) AS SumOfJobValues,
round(Sum(jobs.Earned),2) AS SumOfEarnedValues
FROM jobs
WHERE jobs.PROJID = :pid
GROUP BY jobs.PROJID
as temp ON projects.PROJID = temp.PROJID
SET
projects.VALUE = round(SumOfJobValues,2),
projects.WIP = round(SumOfEarnedValues,2)
WHERE projects.PROJID = :pid";
$command=$connection->createCommand($sql);
$command->bindValue(":pid",$model->PROJID,PDO::PARAM_INT);
$command->execute();