首页 > 学院 > 开发设计 > 正文

SQL语句:统计男女的人数

2019-11-09 13:28:51
字体:
来源:转载
供稿:网友

有student表,按照班级,统计班级的总人数,男生人数和女生人数分别是多少。

sql语句:

select stuClass,count(stuName) 班级人数,sum(case when stuSex='男' then 1 else 0 end ) 男生人数,sum(case when stuSex='女' then 1 else 0 end ) 女生人数from studentgroup by stuClass

执行结果:


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表