为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:dm8
【操作系统】:win11
【CPU】:
【问题描述】*:union all的上部分是全省情况,union all是各地市情况,每段代码单独执行都是正确的,但是一旦用union all拼接起来全省的好像执行了两遍,各地市的好像没执行,实在不知道原因,请专家帮忙看一下,谢谢!!!
案例如下代码:
–全省情况
select jgmc,cj,val1
from(
select jgmc,
nvl(cj,‘小计’)cj,
min(listid)listid,
sum(decode(xfxs, ‘100’, 1, 0))val1
from(
select *
from (select jgid,jgmc, cj,listid
from (select * from tj_base_jg where jgid=‘52001’) a
join (select column_value cj
from table(splitstr(‘国级,省级,市级,县级’, ‘,’))) b
on 1 = 1) x
left join (select cjs,xfxs,bdxfxs,xfrs,dwid,COUNT(1) OVER(PARTITION BY XFJBH,dwid ORDER BY BLSJ ASC,BLFSID ASC) CNT from
(select FIND_AREA_LEVEL(xfcj) cjs, xfxs,bdxfxs, xfrs,decode(1,1,shengid,2,shiid,xianid)dwid,blsj,blfsid,xfjbh
from tj_zh
where isxf = ‘11’
and shiid is not null
and decode(1, 1, shengid, 2, shiid, 3, xianid, zhenid) =
‘52001’)) y
on x.jgid = y.dwid where CNT=1
and x.cj = y.cjs)b group by rollup(cj),jgmc
)
union all
–各地市情况
select jgmc,cj,val1
from(
select jgmc,
nvl(cj,‘小计’)cj,
min(listid)listid,
sum(decode(xfxs, ‘100’, 1, 0))val1
from(
select *
from (select jgid,jgmc, cj,listid
from (select * from tj_base_jg where parentid=‘52001’ and jgid<>‘5200144’) a
join (select column_value cj
from table(splitstr(‘国级,省级,市级,县级’, ‘,’))) b
on 1 = 1) x
left join (select cjs,xfxs,bdxfxs,xfrs,dwid,COUNT(1) OVER(PARTITION BY XFJBH,dwid ORDER BY BLSJ ASC,BLFSID ASC) CNT from
(select FIND_AREA_LEVEL(xfcj) cjs, xfxs,bdxfxs, xfrs,decode(1,1,shiid,xianid)dwid,blsj,blfsid,xfjbh
from tj_zh
where isxf = ‘11’
and shiid is not null
and decode(1, 1, shengid, 2, shiid, 3, xianid, zhenid) =
‘52001’)) y
on x.jgid = y.dwid where CNT=1
and x.cj = y.cjs)b group by rollup(cj),jgmc order by listid,cj
)
上部分和下部分分别执行有多少行,union all和union执行有多少行