• 对一个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))
    

     再简化 

     

  • 相关阅读:
    老李分享:qtp自动化测试框架赏析-关键字自动化测试框架
    QTP自动化测试培训:描述编程之WebElement
    测试开发Python培训:自动发布新浪微博-技术篇
    老李分享:开发python的unittest结果输出样式
    布隆过滤器
    缓存击穿、缓存穿透、缓存雪崩
    JVM锁优化
    Java 异常体系
    常用的SQL调优
    Mysql 索引
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/13999468.html
Copyright © 2020-2023  润新知