MySQL错误代码:1060

时间:2015-03-07 18:02:06

标签: mysql duplicates syntax-error alter-table

所以为此,我们的目标是在名为FullFeePaid的名为ENROLLMENT的表中添加一个列并填充该列(假设为null),但只有两个可能的答案可以是Yes或No来比较另一个名为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;

1 个答案:

答案 0 :(得分:0)

如果评估为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;