select  sClass 班级,count(*)  班级学生总人数,

sum(case when sGender=0 then 1 else 0 end) 女生人数,

sum(case when sGender=0 then 1 else 0 end)*1.0/count(*)女生所占比例,

sum(case when sGender=1 then 1 else 0 end) 男生人数,

sum(case when sGender=1 then 1 else 0 end)*1.0 /count(*)男生所占比例  

from student GROUP BY sClass ORDER BY sClass asc

05-11 16:00