我需要一些帮助来创建正确的选择..。
这是我的桌子:
**teacher** :
id
name
**classroom** :
id
teacher_id
**students** :
id
name
classroom_id
status我正在努力挑选所有有教室的老师。只有当所有学生的地位>10时,才能选择教室。
例如,如果学生的状态为5,那么课堂可能不会被选择,因此老师可能不会被选中(此外,他还有另一个可以选择的教室)
发布于 2013-07-26 03:18:54
试试这个:
select * from teacher t
inner join classroom c on t.id=c.teacher_id
inner join
(select * from students
group by classroom_id having classroom_id not in
(select distinct classroom_id from students where status<=10)) s
on s.classroom_id=c.id更新:根据您的评论,我认为上面的查询应该有效,但是您可以测试这个查询:
select * from teacher t where id in
(select distinct teacher_id from classroom where id in
(select distinct classroom_id from students
group by classroom_id having classroom_id not in
(select distinct classroom_id from students where status<=10)
)
)https://stackoverflow.com/questions/17872111
复制相似问题