zoukankan      html  css  js  c++  java
  • 对一个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))
    

     再简化 

     

  • 相关阅读:
    文件操作
    三级菜单(低端版VS高端版)
    字符串内置方法
    简单购物车的实现
    pandas常用函数
    1.在CentOS 7上安装Docker
    2. IDEA 在同一工作空间创建多个项目
    7.SpringMVC注解@RequestParam全面解析
    6.@RequiresPermissions 注解说明
    1. 构建第一个SpringBoot工程
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/13999468.html
Copyright © 2011-2022 走看看