select t.xb,t.mencount,v.womencount,t.mencount+v.womencount from
(select xb,count(1) as mencount from table where sex='男' group by xb ) t
(select xb,count(1) as womencount from table where sex='女' group by xb ) v
where t.xb=v.xb
select 系别,sum(case when 性别 ='男' then 1 else 0 end ) as 男,
sum(case when 性别 ='女' then 1 else 0 end )as 女,count(*) as 所有总数
from
(
select 'aa' as 姓名, '男' as 性别, '计' as 系别 from dual
union
select 'bb' , '女' , '数' from dual
union
select 'cc' , '男' , '计' from dual
union
select 'dd' , '男' , '数' from dual
)
group by 系别