统计当月人数

select m1=sum(m1),m2=sum(m2),m3=sum(m3),   m4=sum(m4),m5=sum( m5),m6= sum(m6),m7= sum(m7),m8=sum(m8),m9=sum(m9),m10=sum(m10),m11= sum(m11),m12=  sum(m12)from (select personcode,m1=case when  datediff(m,joindate,'2008-01-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-01-1')<=0 then 1 else 0end,m2=case when  datediff(m,joindate,'2008-02-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-02-1')<=0 then 1 else 0end, m3=case when  datediff(m,joindate,'2008-03-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-03-1')<=0 then 1 else 0end ,m4=case when  datediff(m,joindate,'2008-04-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-04-1')<=0 then 1 else 0end ,m5=case when  datediff(m,joindate,'2008-05-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-05-1')<=0 then 1 else 0end ,m6=case when  datediff(m,joindate,'2008-06-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-06-1')<=0 then 1 else 0end ,m7=case when  datediff(m,joindate,'2008-07-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-07-1')<=0 then 1 else 0end ,m8=case when  datediff(m,joindate,'2008-08-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-08-1')<=0 then 1 else 0end ,m9=case when  datediff(m,joindate,'2008-09-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-09-1')<=0 then 1 else 0end ,m10=case when  datediff(m,joindate,'2008-10-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-10-1')<=0 then 1 else 0end ,m11=case when  datediff(m,joindate,'2008-11-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-11-1')<=0 then 1 else 0end ,m12=case when  datediff(m,joindate,'2008-12-1')>=0 and datediff(m,isnull(outDate,'9999-12-12'),'2008-12-1')<=0 then 1 else 0end from  tbperson) as f
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值