SELECT A.ClassName AS 班级名称,
COUNT(ALL A.StudentName) AS 总人数,
SUM( CASE
WHEN Sex = '男' THEN
1
ELSE
0
END
) AS 男生人数,
SUM( CASE
WHEN Sex = '女' THEN
1
ELSE
0
END
) AS 女
FROM [dbo].[Student] A
GROUP BY A.ClassName;