---dt10
SELECT nvl(A.SL,0)+nvl(B.SL,0) AS SL,C.BM AS BM FROM (select SUM(T1.N05) as sl, DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtd_ZD_tb t1,jlqj_wtd_tb t
 where 1=1 AND T1.U_STATE >2
and t.wtd_bh=t1.wtd_bh
and t1.n02 IN (1,4) AND T1.U_STATE IS NOT NULL
GROUP BY DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3)) A,(select count(*) as sl,DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtqj_tb t1 ,jlqj_ydzjjh_tb t,jlqj_wtd_zd_tb wtzd
where 1=1 and t.n02 =1
and wtzd.u_state>2 and t.ydzjjh_bm =t1.d02 
and t1.zd_bm = wtzd.zd_bm
GROUP BY DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3))B,(select distinct bm from (select SUM(T1.N05) as sl, DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtd_ZD_tb t1,jlqj_wtd_tb t
 where 1=1 AND T1.U_STATE >2and t.wtd_bh=t1.wtd_bh
and t1.n02 IN (1,4) AND T1.U_STATE IS NOT NULL
GROUP BY DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3) unionselect count(*) as sl,DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtqj_tb t1 ,jlqj_ydzjjh_tb t,jlqj_wtd_zd_tb wtzd
where 1=1 and t.n02 =1
and wtzd.u_state>2
 and t.ydzjjh_bm =t1.d02 
and t1.zd_bm = wtzd.zd_bm
GROUP BY DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3))) Cwhere A.BM (+)=C.BM and  B.BM (+)=C.BM) xfsl,(
---dt11
SELECT nvl(A.SL,0)+nvl(B.SL,0) AS SL,C.BM AS BM FROM 
(select SUM(T1.N05) as sl, DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtd_ZD_tb t1,jlqj_wtd_tb t
 where 1=1 AND T1.U_STATE >3
and t.wtd_bh=t1.wtd_bh
and t1.n02 IN (1,4) AND T1.U_STATE IS NOT NULL
GROUP BY DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3)) A,
(select count(*) as sl,DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtqj_tb t1 ,jlqj_ydzjjh_tb t,jlqj_wtd_zd_tb wtzd
where 1=1 and t.n02 =1
and wtzd.u_state>3 and t.ydzjjh_bm =t1.d02 
and t1.zd_bm = wtzd.zd_bm
GROUP BY DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3))B,(select distinct bm from (select SUM(T1.N05) as sl, DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtd_ZD_tb t1,jlqj_wtd_tb t
 where 1=1 AND T1.U_STATE >3and t.wtd_bh=t1.wtd_bh
and t1.n02 IN (1,4) AND T1.U_STATE IS NOT NULL
GROUP BY DECODE(t1.N04,23,1,1,1,21,1,25,2,26,3) unionselect count(*) as sl,DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3)as bm from jlqj_wtqj_tb t1 ,jlqj_ydzjjh_tb t,jlqj_wtd_zd_tb wtzd
where 1=1 and t.n02 =1
and wtzd.u_state>3
 and t.ydzjjh_bm =t1.d02 
and t1.zd_bm = wtzd.zd_bm
GROUP BY DECODE(wtzd.N04,23,1,1,1,21,1,25,2,26,3)) Cwhere A.BM (+)=C.BM and  B.BM (+)=C.BM这是两个查询后的语句dt10,dt11,他们的唯一差别在于标记的位置u_state
我想要的结构是select dt10.sl,dt11.sl from dt10,dt11这样的,但是 如果我把dt10,dt11都按上边的写 那太长了,
这个怎么改能短一些?

解决方案 »

  1.   

    简单点---dt10
    select sl from a 
    where u_state>3
    union
    select sl from b
    where u_state>3
    union
    select sl from c
    where u_state>3
    ----dt11
    select sl from a 
    where u_state>4
    union
    select sl from b
    where u_state>4
    union
    select sl from c
    where u_state>4
      

  2.   

    我是lz 那个太复杂了 看这个---dt10
    select sl from a 
    where u_state>3
    union
    select sl from b
    where u_state>3
    union
    select sl from c
    where u_state>3
    ----dt11
    select sl from a 
    where u_state>4
    union
    select sl from b
    where u_state>4
    union
    select sl from c
    where u_state>4我想要的结果是select dt10.sl,dt11.sl from dt10,dt11这样的,但是 如果我把dt10,dt11都按上边的写 那太长了,
    想在一个select dt.sl,dt.sl from dt 中出来上面的样子
      

  3.   

    应该是我没说明白 搞的简单的问题复杂化了
    先说说我的这个东西的意思 
    select dt10.sl wsl,dt11.sl qsl,bm from (slect sl from a where u_state>4) dt10,
    (slect sl from a where u_state>3) dt11 where dt11.bm=dt10.bm大概意思就是上面那个  但是我这个dt10,还有dt11 很长
    通过上面也年看出来 dt10和dt11的差别就在于 u_state,我的想法是可不可以通过一条语句实现我要的结果是这样的
    bm   dt10.sl  dt11.sl
    1      234      567
    2      342     4545
      

  4.   

    select t1.s1 wsl, t2.sl qsl, t1.bm from a t1, a t2
    where t1.u_state > 4
    and t2.u_state > 3
    and t1.bm = t2.bmu_state > 3 中有记录满足 u_state > 4 
    会产生重复数据吧? 
      

  5.   

    问题解决了!用 case when u_state 虽然缩短的很多
    但是还是很长 还是放不了平台上
    最后使用视图解决了
      

  6.   


    --这样?
    select sl from a 
    where u_state>3 and u_state!=4
    union
    select sl from b
    where u_state>3 and u_state!=4
    union
    select sl from c
    where u_state>3 and u_state!=4