我正在尝试进行更新,但似乎一直在遇到这个特定的错误代码。当我运行在外部WHERE子句中找到的嵌套SELECT语句时,我能够提取需要更新的正确条目,但是一旦我尝试运行应该提交更改的完整语句,我就会遇到错误。
UPDATE expertise
SET expertise_level = (expertise_level + 1)
WHERE expertise_level = (SELECT UNIQUE expertise_level, cs.instructor_id
FROM class_section cs JOIN course c ON (cs.course_code = c.course_code)
JOIN expertise e ON (c.course_code = e.course_code)
WHERE (expertise_level < 10) AND (year = '2016'));
我的语法中是否缺少某些内容,或者可能是构建查询的更好方法?谢谢!
答案 0 :(得分:2)
看看你的陈述......
...
WHERE expertise_level = (SELECT UNIQUE expertise_level, cs.instructor_id
FROM class_section
...
怎么可以 &#34; expertise_level&#34;等于&#34; expertise_level,instructor_id&#34; ?
答案 1 :(得分:0)
您的子查询有两列,但只与一个列进行比较。执行所需操作的一种方法是使用相关子查询:
UPDATE expertise
SET expertise_level = expertise_level + 1
WHERE expertise_level = (SELECT expertise_level
FROM class_section cs JOIN
course c
ON cs.course_code = c.course_code
WHERE c.course_code = e.course_code AND
expertise_level < 10 AND
year = '2016'
);
如果可以有多个匹配项,您可能需要使用IN
。
另一个选项使用=
或IN
使用元组:
UPDATE expertise
SET expertise_level = expertise_level + 1
WHERE (course_code, expertise_level) =
(SELECT c.course_code, expertise_level
FROM class_section cs JOIN
course c
ON cs.course_code = c.course_code
WHERE expertise_level < 10 AND
year = '2016'
);
目前还不清楚教练是否应该包含在你的逻辑中;它似乎是语法错误的原因。