学生表student, 班级表cgroup,学生班级关系表groupstu, 不知你有什么其它特殊需要是这样设计, 你为什么不在student加一个班级表id\???/

解决方案 »

  1.   

    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)行不行,执行一下就知道了。
      

  2.   

    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表中没有,那这个学生应该是属于某一个班的,但也统计了出来