from students
group by gender
(查看男女学生各有多少)
注意:从哪种角度分组就从哪列"group by"
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/sqlserver/)对于多重分组,只需将分组规则罗列。比如查询各届各专业的男女同学人数 ,那么分组规则有:届别(grade)、专业(mno)和性别(gender),所以有"group by grade, mno, gender"
select grade, mno, gender, count(*)
from students
group by grade, mno, gender
通常group还和having联用,比如查询1门课以上不及格的学生,则按学号(sno)分类有:
猜你喜欢