试一下
create table tb (UNO int,XM varchar(20),xb char(2))
insert into tb select 1,'tt','男'
union all select 2,'tt2','男'
union all select 3,'tt3','女'
union all select 4,'tt4','女'
select '男生总数' = sum(case when xb='男' then 1 else 0 end),
'女生总数'= sum(case when xb='女' then 1 else 0 end)
from tb