select a.* from student a left join groupstu b on a.id=b.studentid left join cgroup c on b.groupid=c.id where a.sid=学校id and (b.studentid is NULL or c.id is NULL)行不行,执行一下就知道了。
select a.* from student a left join groupstu b on a.id=b.studentid left join cgroup c on b.groupid=c.id where a.sid=学校id and (b.studentid is NULL or c.id is NULL) 出现这样的情况:groupstu表中有两条记录的studentid对应student表中的同一条记录的id,但相应的groupid一个在cgroup表中有,一个在cgroup表中没有,那这个学生应该是属于某一个班的,但也统计了出来
出现这样的情况:groupstu表中有两条记录的studentid对应student表中的同一条记录的id,但相应的groupid一个在cgroup表中有,一个在cgroup表中没有,那这个学生应该是属于某一个班的,但也统计了出来