22,207
社区成员
发帖
与我相关
我的任务
分享
select
EmpStateName 类型,
count(1) 总人数,
sum(case when InCumbency=1 then 1 else 0 end) 在职人数,
convert(varchar(10),sum(case when InCumbency=1 then 1 else 0 end)/count(1)*100)+'%' 在职人数比率,
sum(case when InCumbency=1 then 0 else 1 end) 离职人数,
convert(varchar(10),sum(case when InCumbency=1 then 0 else 1 end)/count(1)*100)+'%' 离职人数比率
from 你的表
group by EmpStateName;--这个才是你的类型
select
类型,
count(1) 总人数,
sum(case when InCumbency=1 then 1 else 0 end) 在职人数,
convert(varchar(10),sum(case when InCumbency=1 then 1 else 0 end)/count(1)*100)+'%' 在职人数比率,
sum(case when InCumbency=1 then 0 else 1 end) 离职人数,
convert(varchar(10),sum(case when InCumbency=1 then 0 else 1 end)/count(1)*100)+'%' 离职人数比率
from 你的表
group by 类型;