select aa.pqid from paper aa where aa.pqid not in (select paper.pqid from paper,answer where paper.pid = answer.pid and paper.pqid= answer.pqid and answer.sid = @sid)
上边的答案虽然是正确的 但不是最优下边更好select aa.pqid from paper aa where aa.pqid not in(select pqid from answer where answer.sid = @sid)
select id from tb2 left join tb1 on tb2.id=tb1.id where tb1.id is null 不能用是因为你要的数据pqid 是在answer中不存在的,绝对不等同与null值 如果库中有笔资料pqid值为null当然可以用is null 查询出来,但是如果不存在数据肯定is null是不可以的
如果把is null 改成 is not null就会查出两个表共同的,但是不会查出不同的:)
这是怎么回事啊??
paper中有pid,pqid.存放的是试卷号为pid的试卷的所有试题。
我现在想查出学号为sid的学生没有答过的题。怎么不能实现呢,弄了一天了,楼上的高手帮帮我啊,先谢谢啦
where aa.pqid not in (select paper.pqid from paper,answer
where paper.pid = answer.pid and
paper.pqid= answer.pqid and
answer.sid = @sid)
where aa.pqid not in(select pqid from answer where answer.sid = @sid)
如果库中有笔资料pqid值为null当然可以用is null 查询出来,但是如果不存在数据肯定is null是不可以的