因此,目标是在名为ENROLLMENT的表FullFeePaid中添加一列并填充该列(假设其为null),但是只有两个可能的答案是"is"或“否”,比较来自另一个表的数据(称为Course)。
因此,我使用alter键入了以下命令,但是即使在从未创建过名为FullFeePaid的列的情况下,我也总是收到重复的消息。
但在此之前,我一直收到错误消息,说那里有语法错误
"set e.FullPaid = if(c.fee - e.amount <= 0 'yes', 'no')".
SET SQL_SAFE_UPDATES = 0;
ALTER TABLE enrollment
add fullfeepaid varchar(45) NULL;
UPDATE ENROLLMENT as e
JOIN COURSE as c on e.CourseNumber = c.CourseNumber
set e.FullFeePaid = if(c.fee - e.amountpaid <= 0 'yes', 'no')
where e.CourseNumber = c.CourseNumber;
select *
from enrollment;
最佳答案
如果条件和结果要返回为true
,则在条件和要返回的结果之间缺少逗号:
UPDATE ENROLLMENT as e
JOIN COURSE as c on e.CourseNumber = c.CourseNumber
SET e.FullFeePaid = if(c.fee - e.amountpaid <= 0, 'yes', 'no')
-- Missing comma in the OP ---------------------^
WHERE e.CourseNumber = c.CourseNumber;
关于mysql - MySQL错误代码: 1060,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28918178/