面试之SQL(1)--选出选课数量>=2的学号
ID Course
1 | AA |
1 | BB |
2 | AA |
2 | BB |
2 | CC |
3 | AA |
3 | BB |
3 | CC |
3 | DD |
4 | AA |
NULL | NULL |
选出选课数量>=2的学号
select distinct ID from test as A
where (Select count(ID) from test as B where A.ID=B.ID)>=2
1
2
3
ID Course
1 | AA |
1 | BB |
2 | AA |
2 | BB |
2 | CC |
3 | AA |
3 | BB |
3 | CC |
3 | DD |
4 | AA |
NULL | NULL |
选出选课数量>=2的学号
select distinct ID from test as A
where (Select count(ID) from test as B where A.ID=B.ID)>=2
1
2
3