高手进,求sql语句

来源:百度知道 编辑:UC知道 时间:2024/05/24 00:06:47
员工表employee , 其中有一个字段为性别 (xb0000),1表示为男,2表示为女,求sql语句,一次性将员工人数,男员工数,女员工数显示出来。(用一个select count(*) ,不要用三个select count(*))。

如果xb0000为数值型:
select count(*) as 员工人数,sum(case xb0000 when 1 then 1 else 0 end) as 男员工数,sum(case xb0000 when 2 then 1 else 0 end) as 女员工数 from employee

如果xb0000为字符:
select count(*) as 员工人数,sum(case xb0000 when '1' then 1 else 0 end) as 男员工数,sum(case xb0000 when '2' then 1 else 0 end) as 女员工数 from employee

以上,希望对你有所帮助!

select decode(xb0000,'1',count(1)),decode(xb0000,'2',count(1)),count(1) from employee.