如何一次更新2列?
我尝试了以下声明,但不起作用:
UPDATE exercises
SET times_answered = times_answered + 1
AND av_answeringTime = av_answeringTime + ( (av_answeringTime / (times_answered) ) + ?) * (times_answered + 1)
WHERE name = ?
答案 0 :(得分:48)
使用逗号而不是“AND”:
UPDATE exercises
SET times_answered = times_answered + 1,
av_answeringTime = av_answeringTime + ( (av_answeringTime / (times_answered) ) + ?) * (times_answered + 1)
WHERE name = ?
答案 1 :(得分:29)
SQL UPDATE语法是:
UPDATE table SET
column1 = value1,
column2 = value2
WHERE condition
而不是AND,你需要一个逗号
答案 2 :(得分:6)
尝试这样的事情......
UPDATE exercises
SET times_answered = times_answered + 1,
av_answeringTime = av_answeringTime + ( (av_answeringTime / (times_answered) ) + ?) * (times_answered + 1)
WHERE name = ?