对一个sql的分析

 select *
   FROM LPEdorItem a, LCCont b, LPEdorApp c
  WHERE a.edoracceptno = c.edoracceptno
    and a.ContNo = b.ContNo
    and b.appntno = '0000235356'
    AND b.conttype = '1' --'2-集体总单,1-个人总投保单';
    AND (c.AppType != '6' OR c.AppType is null) -- 申请方式
    and a.edorvalidate >= trunc(sysdate) - 365
    and a.edorvalidate <= trunc(sysdate)
    and c.makedate between to_date('20190101', 'yyyy-mm-dd') and
        to_date('20201117', 'yyyy-mm-dd')
    and b.familytype <> '1'
    and (case
          when a.edorstate in ('0', 'j', '4', '9', 'c', 'd') and
               (not exists (select 1
                              from ljaget t
                             where t.otherno = a.edoracceptno
                               and t.confdate is null
                               and t.sumgetmoney <> 0) or EXISTS
                (SELECT 1
                   FROM LJMONETARYSTERILIZATIONB LJM
                  WHERE LJM.OTHERNO = A.contno)) then
           '1'
          else
           '0'
        end) = '1'

 简化

-->>>>这两个是等同的
select *
  from LPEdorItem a
 where (case
         when a.edorstate in ('0', 'j', '4', '9', 'c', 'd')then
          '1'
         else
          '0'
       end) = '1'
--------------------------------------------------------------------------------
select * from LPEdorItem a where a.edorstate in ('0', 'j', '4', '9', 'c', 'd')

 解释: { when 条件 then '1'}= '1' 这等同于where条件  where a.edorstate in ('0', 'j', '4', '9', 'c', 'd')

select *
  from LPEdorItem a
 where (not exists (select 1
                      from ljaget t --实付总表
                     where t.otherno = a.edoracceptno
                       and t.confdate is null  --财务确认日期
                       and t.sumgetmoney <> 0) --总给付金额
                        or EXISTS 
        (SELECT 1
           FROM LJMONETARYSTERILIZATIONB LJM
          WHERE LJM.OTHERNO = A.contno))

 再简化 

 

posted @ 2020-11-18 14:05  张艳涛&java  阅读(115)  评论(0编辑  收藏  举报