union一例,oracle上的union会自动把重复的列去掉

--当该人是选案人员时
select qt.ajbh, qt.lrajbh, nsr.nsrsbh, nsr.nsrmc, jg.swjg_mc, zt.jczt_mc, qt.sfla
from 
    ctais2wg.t03_qtajxx qt
   ,ctais2wg.t03_ayxsqc ay
   ,ctais2wg.dm_jczt zt
   ,ctais2wg.dj_nsrxx nsr
   ,ctais2wg.dm_swjg jg
where
      qt.AYXSCLR_DM = '14401000192'                 --该人是选案经办人
  and qt.AJZXWBRQ is null                           --该案件没有执行完毕
  and (sysdate - qt.ZGAJWCRQ) > 25                  --已经超出原定完成日期特定的天数
  and (
        qt.AYCLRQ is not null and qt.JCRWXDRQ is null
      )                                             --该案件仍然在选案环节没有做完
  and qt.ajbh = ay.ajbh
  and qt.jczt_dm = zt.jczt_dm
  and ay.LRDW_BM = jg.swjg_dm
  and ay.nsrsbh = nsr.nsrsbh
union
--当该人是检查人员时
select qt.ajbh, qt.lrajbh, nsr.nsrsbh, nsr.nsrmc, jg.swjg_mc, zt.jczt_mc, qt.sfla
from 
    ctais2wg.t03_qtaj_jcry jcr
   ,ctais2wg.t03_qtajxx qt
   ,ctais2wg.t03_ayxsqc ay
   ,ctais2wg.dm_jczt zt
   ,ctais2wg.dj_nsrxx nsr
   ,ctais2wg.dm_swjg jg
where
      jcr.jcry_dm = '14401000192'           --该人负责检查环节
  and jcr.yxbz = 'Y'                     
  and jcr.ajbh = qt.ajbh                    --该人负责的检查环节中包含该案件的检查环节
  and qt.AJZXWBRQ is null                   --该案件没有执行完毕
  and (sysdate - qt.ZGAJWCRQ) > 25          --已经超出原定完成日期特定的天数
  and (
        (qt.sfla='Y' and qt.JCRWXDRQ is not null and qt.TJSLSRQ is null)
         or              
        (qt.sfla='N' and qt.JCRWXDRQ is not null and qt.CLJDSFSRQ is null and qt.JCJLFSRQ is null)
      )                                     --该案件的检查环节仍然没有做完
  --and qt.JCRWXDRQ is not null and qt.TJSLSRQ is null and qt.CLJDSFSRQ is null and qt.JCJLFSRQ is null   --考虑到速度问题时可以用这条代替‘检查环节没完成’的功能
  and qt.ajbh = ay.ajbh
  and qt.jczt_dm = zt.jczt_dm
  and ay.LRDW_BM = jg.swjg_dm
  and ay.nsrsbh = nsr.nsrsbh
union
--当该人是审理人员时
select qt.ajbh, qt.lrajbh, nsr.nsrsbh, nsr.nsrmc, jg.swjg_mc, zt.jczt_mc, qt.sfla
from 
    ctais2wg.t03_qtaj_slry slr
   ,ctais2wg.t03_qtajxx qt
   ,ctais2wg.t03_ayxsqc ay
   ,ctais2wg.dm_jczt zt
   ,ctais2wg.dj_nsrxx nsr
   ,ctais2wg.dm_swjg jg
where
      slr.slry_dm = '14401000192'           --该人负责审理环节
  and slr.yxbz = 'Y'                     
  and slr.ajbh = qt.ajbh                    --该人负责的审理环节中包含该案件的检查环节
  and qt.AJZXWBRQ is null                   --该案件没有执行完毕
  and (sysdate - qt.ZGAJWCRQ) > 25          --已经超出原定完成日期特定的天数
  and (
        (qt.sfla='Y' and qt.TJSLSRQ is not null 
            and qt.CLJDSFSRQ is null and qt.JCJLFSRQ is null --非重大审
            and qt.ZDSWASLTQSRQ is null)  --重大审
      )                                     --该案件的审理环节仍然没有做完
  and qt.ajbh = ay.ajbh
  and qt.jczt_dm = zt.jczt_dm
  and ay.LRDW_BM = jg.swjg_dm
  and ay.nsrsbh = nsr.nsrsbh
union
--当该人是执行人员
select qt.ajbh, qt.lrajbh, nsr.nsrsbh, nsr.nsrmc, jg.swjg_mc, zt.jczt_mc, qt.sfla
from 
    ctais2wg.t03_qtaj_zxry zxr
   ,ctais2wg.t03_qtajxx qt
   ,ctais2wg.t03_ayxsqc ay
   ,ctais2wg.dm_jczt zt
   ,ctais2wg.dj_nsrxx nsr
   ,ctais2wg.dm_swjg jg
where
      zxr.zxry_dm = '14401000192'           --该人负责执行环节
  and zxr.yxbz = 'Y'                     
  and zxr.ajbh = qt.ajbh                    --该人负责的执行环节中包含该案件的检查环节
  and qt.AJZXWBRQ is null                   --该案件没有执行完毕
  and (sysdate - qt.ZGAJWCRQ) > 25          --已经超出原定完成日期特定的天数
  and (       
           qt.CLJDSFSRQ is not null or qt.JCJLFSRQ is not null           
      )                                     --该案件的执行环节仍然没有做完
  and qt.ajbh = ay.ajbh
  and qt.jczt_dm = zt.jczt_dm
  and ay.LRDW_BM = jg.swjg_dm
  and ay.nsrsbh = nsr.nsrsbh

你可能感兴趣的:(oracle,qt)