mysql-查询的案例

查询每个专业的男生人数和女生人数分别是多少

#方式一:
select count(*) 个数,sex,majorid from student group by sex,majorid;
#方式二:
select majorid,
(select count(*) from student where sex='' and majorid=s.majorid)男,
(select count(*) from student where sex='' and majorid=s.majorid)女
from student s
group by majorid;

猜你喜欢

转载自www.cnblogs.com/yangche/p/10679870.html