我正在尝试使用case语句更新记录集合,但得到:
错误:#1064-您的SQL语法有错误;查看手册 对应于您的MySQL服务器版本的正确语法, 在'FROM(SELECT SoftwareProjects.id, SoftwareProjects.Project_Code,
Description
',位于第8行
这是我的查询
UPDATE SoftwareProjects
SET BudgetStatus =
CASE
WHEN ((HoursBooked/HoursEstimated) * (100/1) < 80) THEN 1
WHEN ((HoursBooked/HoursEstimated) * (100/1) > 81 && (HoursBooked/HoursEstimated) * (100/1) < 100 ) THEN 2
ELSE 3
END
FROM
(SELECT SoftwareProjects.id, SoftwareProjects.Project_Code, Description,
BudgetStatus, TimelineStatus, QualityStatus, OverallStatus,
DeliveryDate, HoursEstimated, s4_project_id,
SUM( hours_adjusted ) AS HoursBooked
FROM SoftwareProjects
LEFT JOIN S4Admin.ts_entries ON s4_project_id =
S4Admin.ts_entries.project
GROUP BY Description
ORDER BY SoftwareProjects.Description)
答案 0 :(得分:2)
尝试以下
UPDATE SoftwareProjects a
JOIN
(SELECT SoftwareProjects.id, SoftwareProjects.Project_Code, Description, BudgetStatus, TimelineStatus, QualityStatus, OverallStatus, DeliveryDate, HoursEstimated, s4_project_id, SUM( hours_adjusted ) AS HoursBooked
FROM SoftwareProjects
LEFT JOIN S4Admin.ts_entries ON s4_project_id =
S4Admin.ts_entries.project
GROUP BY Description
ORDER BY SoftwareProjects.Description) b on a.id=b.id
SET a.BudgetStatus =
CASE
WHEN ((HoursBooked/b.HoursEstimated) * (100/1) < 80) THEN 1
WHEN ((HoursBooked/b.HoursEstimated) * (100/1) > 81 && (HoursBooked/b.HoursEstimated) * (100/1) < 100 ) THEN 2
ELSE 3
END