select classId, sum(case when gender='男' then 1 else 0 end) as '男', sum(case when gender='女' then 1 else 0 end) as '女' from student group by classId