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;

 

posted @ 2019-04-09 21:24  无畏D尘埃  阅读(217)  评论(0编辑  收藏  举报