一则Sql统计的语句

select * from EnterpriseInfo


select * ,CharIndex('存在加班工资发放不足隐患|无证照经营',DisputeReason) from LabourCapitalDispute

select a.*,EnterpriseType from LabourCapitalDispute a left join EnterpriseInfo on EnterpriseName = EnterpriseInfo.name 


select a.*,EnterpriseType from LabourCapitalDispute a left join EnterpriseInfo b on a.EnterpriseName = b.name 



select count(1) total 
    ,
sum(case when b.EnterpriseType='台资企业' then 1 else 0 end) bc_tz --排查企业
    ,Sum(Case When b.EnterpriseType='日资企业' then 1 else 0 end) bc_rz
    ,
Sum(Case When b.EnterpriseType='其他外资企业' then 1 else 0 end) bc_qtwz
    ,
Sum(Case When b.EnterpriseType='民营企业' then 1 else 0 end) bc_my
    ,
Sum(Case When b.EnterpriseType='其他' then 1 else 0 end) bc_qt
    ,
Sum(Case When CharIndex('调处化解',a.DisputeReason) > 0 then 1 else 0 end) tcfj_xj  --调处化解
    ,Sum(Case When CharIndex('调处化解',a.DisputeReason) > 0 and b.EnterpriseType='台资企业' then 1 else 0 end) tcfj_tz
    ,
Sum(Case When CharIndex('调处化解',a.DisputeReason) > 0 and b.EnterpriseType='日资企业' then 1 else 0 end) tcfj_rz
    ,
Sum(Case When CharIndex('调处化解',a.DisputeReason) > 0 and b.EnterpriseType='其他外资企业' then 1 else 0 end) tcfj_qtwz
    ,
Sum(Case When CharIndex('调处化解',a.DisputeReason) > 0 and b.EnterpriseType='民营企业' then 1 else 0 end) tcfj_my
    ,
Sum(Case When CharIndex('调处化解',a.DisputeReason) > 0 and b.EnterpriseType='其他' then 1 else 0 end) tcfj_qt
    ,
Sum(Case When CharIndex('未按合同法要求签订劳动合同',a.DisputeReason) > 0 then 1 else 0 end) waht_xj  --未按合同法要求签订劳动合同
    ,Sum(Case When CharIndex('未按合同法要求签订劳动合同',a.DisputeReason) > 0 and b.EnterpriseType='台资企业' then 1 else 0 end) waht_tz
    ,
Sum(Case When CharIndex('未按合同法要求签订劳动合同',a.DisputeReason) > 0 and b.EnterpriseType='日资企业' then 1 else 0 end) waht_rz
    ,
Sum(Case When CharIndex('未按合同法要求签订劳动合同',a.DisputeReason) > 0 and b.EnterpriseType='其他外资企业' then 1 else 0 end) waht_qtwz
    ,
Sum(Case When CharIndex('未按合同法要求签订劳动合同',a.DisputeReason) > 0 and b.EnterpriseType='民营企业' then 1 else 0 end) waht_my
    ,
Sum(Case When CharIndex('未按合同法要求签订劳动合同',a.DisputeReason) > 0 and b.EnterpriseType='其他' then 1 else 0 end) waht_qt
    ,
Sum(Case When CharIndex('存在加班工资发放不足隐患',a.DisputeReason) > 0 then 1 else 0 end) czjb_xj  --存在加班工资发放不足隐患
    ,Sum(Case When CharIndex('存在加班工资发放不足隐患',a.DisputeReason) > 0 and b.EnterpriseType='台资企业' then 1 else 0 end) czjb_tz
    ,
Sum(Case When CharIndex('存在加班工资发放不足隐患',a.DisputeReason) > 0 and b.EnterpriseType='日资企业' then 1 else 0 end) czjb_rz
    ,
Sum(Case When CharIndex('存在加班工资发放不足隐患',a.DisputeReason) > 0 and b.EnterpriseType='其他外资企业' then 1 else 0 end) czjb_qtwz
    ,
Sum(Case When CharIndex('存在加班工资发放不足隐患',a.DisputeReason) > 0 and b.EnterpriseType='民营企业' then 1 else 0 end) czjb_my
    ,
Sum(Case When CharIndex('存在加班工资发放不足隐患',a.DisputeReason) > 0 and b.EnterpriseType='其他' then 1 else 0 end) czjb_qt
    ,
Sum(Case When CharIndex('存在企业运营困难隐患',a.DisputeReason) > 0 then 1 else 0 end) czqy_xj  --存在企业运营困难隐患
    ,Sum(Case When CharIndex('存在企业运营困难隐患',a.DisputeReason) > 0 and b.EnterpriseType='台资企业' then 1 else 0 end) czqy_tz
    ,
Sum(Case When CharIndex('存在企业运营困难隐患',a.DisputeReason) > 0 and b.EnterpriseType='日资企业' then 1 else 0 end) czqy_rz
    ,
Sum(Case When CharIndex('存在企业运营困难隐患',a.DisputeReason) > 0 and b.EnterpriseType='其他外资企业' then 1 else 0 end) czqy_qtwz
    ,
Sum(Case When CharIndex('存在企业运营困难隐患',a.DisputeReason) > 0 and b.EnterpriseType='民营企业' then 1 else 0 end) czqy_my
    ,
Sum(Case When CharIndex('存在企业运营困难隐患',a.DisputeReason) > 0 and b.EnterpriseType='其他' then 1 else 0 end) czqy_qt
    ,
Sum(Case When CharIndex('无证照经营',a.DisputeReason) > 0 then 1 else 0 end) wzzj_xj  --无证照经营
    ,Sum(Case When CharIndex('无证照经营',a.DisputeReason) > 0 and b.EnterpriseType='台资企业' then 1 else 0 end) wzzj_tz
    ,
Sum(Case When CharIndex('无证照经营',a.DisputeReason) > 0 and b.EnterpriseType='日资企业' then 1 else 0 end) wzzj_rz
    ,
Sum(Case When CharIndex('无证照经营',a.DisputeReason) > 0 and b.EnterpriseType='其他外资企业' then 1 else 0 end) wzzj_qtwz
    ,
Sum(Case When CharIndex('无证照经营',a.DisputeReason) > 0 and b.EnterpriseType='民营企业' then 1 else 0 end) wzzj_my
    ,
Sum(Case When CharIndex('无证照经营',a.DisputeReason) > 0 and b.EnterpriseType='其他' then 1 else 0 end) wzzj_qt
    ,
Sum(Case When a.IsUnstableAspect = 1 then 1 else 0 end) czqt_xj  --存在其他不稳定因素
    ,Sum(Case When a.IsUnstableAspect = 1 and b.EnterpriseType='台资企业' then 1 else 0 end) czqt_tz
    ,
Sum(Case When a.IsUnstableAspect = 1 and b.EnterpriseType='日资企业' then 1 else 0 end) czqt_rz
    ,
Sum(Case When a.IsUnstableAspect = 1 and b.EnterpriseType='其他外资企业' then 1 else 0 end) czqt_qtwz
    ,
Sum(Case When a.IsUnstableAspect = 1 and b.EnterpriseType='民营企业' then 1 else 0 end) czqt_my
    ,
Sum(Case When a.IsUnstableAspect = 1 and b.EnterpriseType='其他' then 1 else 0 end) czqt_qt
    ,
Sum(DealPersonCount) DealPersonCount
from LabourCapitalDispute
left join EnterpriseInfo b on a.EnterpriseName = b.name 


存在加班工资发放不足隐患|无证照经营
posted @ 2009-05-22 17:37  Sam Lin  阅读(352)  评论(0编辑  收藏  举报