层级sql

表一、在2020-11-30前(含11.30),符合条件的有效职位数明细,条件如下:
①    数据项:所属集团全称、所属企业全称、对应有效职位数、需求人数总数(若干=5)
②    企业范围:企业性质为国有企业、中央企业、央管协会单位

表二、在2020-08-10后(含8.10),符合条件的有效职位数明细,条件如下:
①    数据项:所属集团全称、所属企业全称、对应有效职位数、需求人数总数(若干=5)
②    企业范围:企业性质为国有企业、中央企业、央管协会单位

declare @#Tmp_Comp table (id UNIQUEIDENTIFIER, rootid UNIQUEIDENTIFIER, [level] int)
--获取集团公司
insert into @#Tmp_Comp (id, rootid, [level])
select CompanyId, CompanyId, 1
from Biz_Company
where companytype in ('GSXZ0103','GSXZ0113','GSXZ0114')
and IsGroupCompany = 1 and GroupCompanyId is not null


--获取一级子公司
insert into @#Tmp_Comp (id, rootid, [level])
select CompanyId, CT.id, 2
from Biz_Company C
    inner join @#Tmp_Comp CT on CT.id = C.ParentCompanyId and [level] = 1

--获取二级子公司
insert into @#Tmp_Comp (id, rootid, [level])
select C.CompanyId, CT.id, 3
from Biz_Company C
    inner join @#Tmp_Comp CT on CT.id = C.ParentCompanyId and [level] = 2

    
--select * from @#Tmp_Comp

select cr.CompanyName as N'所属集团全称',c.CompanyName as N'所属企业全称',count(cr.CompanyName) as N'有效职位数',sum( case when j.RecruitmentNum = 0 then 5 else j.RecruitmentNum  end ) as N'需求人数总数'  from @#Tmp_Comp t
inner join Biz_Company cr
on cr.CompanyId = t.rootid
inner join Biz_Company c
on c.CompanyId = t.id
inner join Biz_JobPosition j
on c.CompanyId = j.CompanyId
where j.status = 1 and j.auditstatus = 2
and j.ExpredTime >= '2020-11-30'
group by cr.CompanyName,c.CompanyName

select cr.CompanyName as N'所属集团全称',c.CompanyName as N'所属企业全称',count(cr.CompanyName) as N'有效职位数',sum( case when j.RecruitmentNum = 0 then 5 else j.RecruitmentNum  end ) as N'需求人数总数'  from @#Tmp_Comp t
inner join Biz_Company cr
on cr.CompanyId = t.rootid
inner join Biz_Company c
on c.CompanyId = t.id
inner join Biz_JobPosition j
on j.CompanyId = c.CompanyId 
where j.status = 1 and j.auditstatus = 2
and J.PublishTime >= '2020-08-10'
group by cr.CompanyName,c.CompanyName

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值