日期:2014-05-17 浏览次数:20742 次
with a(meetingID, meetingAreaID, meetingName) as (
select 1, 1, '人代会' union all
select 2, 2, '江苏政协一次会议' union all
select 3, 4, '南京人大' union all
select 4, 1, '全国劳模表彰' union all
select 5, 3, '浙江工商业大会'
)
,b(areaID , areaName, parentID) as(
select 1, '全国', null union all
select 2, '江苏', 1 union all
select 3, '浙江', 1 union all
select 4, '南京', 2
),c as(
select meetingareaid as a,count(meetingareaid) b from a
group by meetingareaid
)
,d as(
select areaname a,parentid d,isnull(areaID,0) c,c.b from b left join c on b.areaID=c.a
)
,e as(
select a , c, d=c, b from d
union all
select e.a , d.c, e.d, d.b from e,d where d.d=e.c
)
select a,sum(b) from e
group by a
option ( maxrecursion 0)