这是我的表[answer]和[student_answer]
create table answer(
varchar2(10) ques_id,
varchar2(10) ans,
primary key (ques_id)
);
create table student_answer(
varchar2(10) stud_id,
varchar2(10) quiz_id,
varchar2(10) ques_id,
varchar2(10) ans,
number(3) mark,
primary key (stud_id,quiz_id,ques_id)
);
UPDATE student_answer
SET mark = 1
WHERE * IN (select ques_id, stud_id, quiz_id from answer m
right outer join student_answer sa
on (sa.ques_id = m.ques_id and sa.ans=m.ans)
where m.ques_id is not null
order by sa.ques_id);
*我在这里感到困惑
如何为每个子查询获得多行输出?这样我可以根据结果更新表格吗?
* every student have different id
* every quiz have different id
* every question have different id
答案 0 :(得分:1)
要使用IN
,您必须在左侧只有一列,并且该列的可能性在右侧。
但我认为你可以用UPDATE
做EXISTS
。试试这个:
UPDATE student_answer sa
SET mark = 1
WHERE EXISTS (
SELECT 1
FROM answer m
WHERE sa.ques_id = m.ques_id
AND sa.ans = m.ans
);