怎么选中同时选了1和2课的学生,比如在图中,要如何获取到1和4学生
select t1.a from test t1 join test t2 on t1.a=t2.a where t1.b=1 and t2.b=2
如你所说 a代表学生,b代表课。选课1和2的学生这也太简单了。 where and 连接即可。
select a from test where b=1 or b=2
select * from test
where a in (1,4) or b in(1,4)
请采纳
select a from test where b=1 and a in (select a from test where b=2);
select t1.a from test t1 , test t2 where t1.a=t2.a and (t1.b=1 and t2.b=2)