码迷,mamicode.com
首页 > 其他好文 > 详细

123131

时间:2016-06-02 19:42:37      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

SELECT      edr_comm_prem*1.0 as 手续费,
            EDR_PERFORMANCE_ACTUAL_FEE*1.0 AS 复核绩效,
            EDR_FULLPERFORMANCE_FEE*1.0 AS 全绩效,
           EDR_APPROVABLE_ELSE_CHARGE_FEE*1.0 AS 日展费
  FROM (SELECT TRUNC(GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME)) AS STAT_YM,
               A.DEPARTMENT_CODE AS DEPARTMENT_CODE,
               A.PLAN_CODE AS PLAN_CODE,
               A.BUSINESS_TYPE AS BUSINESS_TYPE,
               A.BUSINESS_SOURCE_CODE AS BUSINESS_SOURCE_CODE,
               A.BUSINESS_SOURCE_DETAIL_CODE AS BUSINESS_SOURCE_DETAIL_CODE,
               A.BUSINESS_SOURCE_CODE || A.BUSINESS_SOURCE_DETAIL_CODE ||
               A.CHANNEL_SOURCE_CODE ||
               DECODE(A.CHANNEL_SOURCE_DETAIL_CODE,
                      ‘ ‘,
                      ‘0‘,
                      NVL(A.CHANNEL_SOURCE_DETAIL_CODE, ‘0‘)) AS THREE,
               A.BUSINESS_SOURCE_CODE || A.BUSINESS_SOURCE_DETAIL_CODE ||
               A.CHANNEL_SOURCE_CODE ||
               DECODE(A.CHANNEL_SOURCE_DETAIL_CODE,
                      ‘ ‘,
                      ‘0‘,
                      NVL(A.CHANNEL_SOURCE_DETAIL_CODE, ‘0‘)) AS FIVE,
               A.BUSINESS_SOURCE_CODE || A.BUSINESS_SOURCE_DETAIL_CODE ||
               A.CHANNEL_SOURCE_CODE ||
               DECODE(A.CHANNEL_SOURCE_DETAIL_CODE,
                      ‘ ‘,
                      ‘0‘,
                      NVL(A.CHANNEL_SOURCE_DETAIL_CODE, ‘0‘)) AS EIGHT,
               SUBSTRB(DECODE(A.PLAN_CODE,
                              ‘A00‘,
                              A.C_TGT1,
                              ‘A01‘,
                              A.C_TGT1,
                              ‘A02‘,
                              A.C_TGT1,
                              ‘A03‘,
                              A.C_TGT1,
                              ‘A15‘,
                              A.C_TGT8,
                              ‘A19‘,
                              (DECODE(A.DATA_SOURCE, ‘E‘, A.C_TGT9, A.C_TGT5)),
                              ‘A37‘,
                              (DECODE(A.DATA_SOURCE, ‘E‘, A.C_TGT13, A.C_TGT1)),
                              ‘A39‘,
                              A.C_TGT8,
                              ‘无‘),
                       1,
                       50) AS PROPERTY_TRADE,
               SUBSTRB(DECODE(A.PLAN_CODE,
                              ‘A33‘,
                              A.C_TGT8,
                              ‘A04‘,
                              A.C_TGT12,
                              ‘A32‘,
                              A.C_TGT12,
                              ‘无‘),
                       1,
                       50) AS MACHINE_TRADE3,
               SUBSTRB(DECODE(A.PLAN_CODE,
                              ‘A13‘,
                              NVL(A.C_TGT19, A.C_TGT18),
                              ‘A14‘,
                              NVL(A.C_TGT19, A.C_TGT18),
                              ‘无‘),
                       1,
                       50) AS BUILDING_TYPE3,
               SUBSTRB(DECODE(B.INSURANCE_SECT, ‘B‘, A.C_TGT1, ‘无‘), 1, 50) AS CARGO_TYPE,
               A.PERFORMANCE_LEVEL AS PERFORMANCE_LEVEL,
               DECODE(A.C_EDR_TYP,
                      ‘1‘,
                      DECODE(SIGN(A.N_PRM_VAR - 0), -1, 1, 0),
                      0) AS EDR_MINUS_NUM, --批减笔数
               DECODE(A.C_EDR_TYP,
                      ‘1‘,
                      DECODE(SIGN(A.N_PRM_VAR - 0),
                             -1,
                             A.N_PRM_VAR * C.N_CHG_RTE,
                             0),
                      0) AS EDR_MINUS_PREM, --批减保费
               DECODE(A.C_EDR_TYP, ‘2‘, -1, ‘8‘, 1, ‘0‘) AS ZT_NUM, --注退件数
               A.N_PRM_VAR * C.N_CHG_RTE AS EDR_PREM,
               A.CEDING_TYPE_CODE AS CEDING_TYPE_CODE,
               A.LAST_POLICY_NO AS LAST_POLICY_NO,
               A.PARENT_COMPANY_CODE AS PARENT_COMPANY_CODE,
               A.XMLB_MARK,
               CASE
                 WHEN B.INSURANCE_SECT = ‘A‘ AND
                      A.PLAN_CODE NOT IN (‘A04‘, ‘A32‘, ‘A33‘) AND
                      A.PERFORMANCE_LEVEL = ‘鼓励承保业务‘ THEN
                  ‘1‘
                 WHEN B.INSURANCE_SECT = ‘A‘ AND
                      A.PLAN_CODE NOT IN (‘A04‘, ‘A32‘, ‘A33‘) AND
                      A.PERFORMANCE_LEVEL IN (‘谨慎承保业务‘, ‘一般承保业务‘) AND
                      TRIM(A.XMLB_MARK) IN (‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘) AND
                      A.PARENT_COMPANY_CODE IS NOT NULL THEN
                  ‘1‘
                 WHEN A.PLAN_CODE IN (‘A04‘, ‘A32‘, ‘A33‘) AND
                      A.PERFORMANCE_LEVEL IN (‘鼓励承保业务‘, ‘一般承保业务‘) THEN
                  ‘1‘
                 WHEN B.INSURANCE_SECT = ‘E‘ AND
                      A.PERFORMANCE_LEVEL IN (‘鼓励承保业务‘, ‘一般承保业务‘) THEN
                  ‘1‘
                 WHEN B.INSURANCE_SECT = ‘B‘ THEN
                  ‘1‘
                 WHEN B.INSURANCE_SECT = ‘D‘ THEN
                  ‘1‘
                 WHEN B.INSURANCE_SECT = ‘H‘ AND A.PLAN_CODE <> ‘A56‘ THEN
                  ‘1‘
                 WHEN B.INSURANCE_SECT = ‘I‘ THEN
                  ‘1‘
                 ELSE
                  ‘0‘
               END AS IS_HIGHQUALITY,
               T.EDR_COMM_PREM * C.N_CHG_RTE AS EDR_COMM_PREM,
               T.EDR_CHANGEFEE_FEE * C.N_CHG_RTE AS EDR_CHANGEFEE_FEE,
               T.EDR_PERFORMANCE_ACTUAL_FEE * C.N_CHG_RTE AS EDR_PERFORMANCE_ACTUAL_FEE,
               T.EDR_TRANSFORMFEE_FEE * C.N_CHG_RTE AS EDR_TRANSFORMFEE_FEE,
               T.EDR_FULLPERFORMANCE_FEE * C.N_CHG_RTE AS EDR_FULLPERFORMANCE_FEE,
               T.EDR_APPROVABLE_ELSE_CHARGE_FEE * C.N_CHG_RTE AS EDR_APPROVABLE_ELSE_CHARGE_FEE,
               T.EDR_APP_ELSE_CHARGE_FEE2 * C.N_CHG_RTE AS EDR_APP_ELSE_CHARGE_FEE2,
               SUBSTRB(DECODE(A.PLAN_CODE, ‘B04‘, A.C_TGT6, NULL), 1, 10) BUILDYEAR,
               (CASE
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 IS NULL THEN
                  ‘909‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > -1 AND
                      A.N_NUMBER9 <= 200 THEN
                  ‘900‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 200 AND
                      A.N_NUMBER9 <= 500 THEN
                  ‘901‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 500 AND
                      A.N_NUMBER9 <= 1000 THEN
                  ‘902‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 1000 AND
                      A.N_NUMBER9 <= 3000 THEN
                  ‘903‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 3000 AND
                      A.N_NUMBER9 <= 5000 THEN
                  ‘904‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 5000 AND
                      A.N_NUMBER9 <= 10000 THEN
                  ‘905‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 10000 AND
                      A.N_NUMBER9 <= 20000 THEN
                  ‘906‘
                 WHEN A.PLAN_CODE = ‘B04‘ AND A.N_NUMBER9 > 20000 THEN
                  ‘907‘
               END) AS TOTALTON,
               SUBSTRB(DECODE(A.PLAN_CODE, ‘B04‘, A.C_TGT13, NULL), 1, 10) AS SHIPPINGTYPE,
               A.BUSI_TYPE,
               DECODE(LENGTH(A.INPUT_BY),
                      LENGTH(REPLACE(A.INPUT_BY, ‘-‘)),
                      1,
                      0) INOUTSIDE_TYPE,
               T.AGREEMENT_TYPE,
               A.AGENT_CODE,
               A.BROKER_CODE,
               A.PRODUCT_CODE,
               A.COINSURANCE_MARK,
               A.N_AMT_VAR * D.N_CHG_RTE AS TOTAL_INSURED_AMOUNT,
               TO_CHAR(CASE
                         WHEN E.INSURANCE_COST_RATE IS NULL THEN
                          1200
                         WHEN E.INSURANCE_COST_RATE < 0 THEN
                          1201
                         ELSE
                          (SELECT T4.PREM
                             FROM EPCIS_NL_PREM_SEG_RIGHT T4
                            WHERE T4.FLAG = ‘C‘
                              AND ((E.INSURANCE_COST_RATE > T4.LOWER_LIMIT AND
                                  T4.UPPER_LIMIT IS NULL) OR
                                  (E.INSURANCE_COST_RATE > T4.LOWER_LIMIT AND
                                  E.INSURANCE_COST_RATE <= T4.UPPER_LIMIT)))
                       END) AS INSURANCE_COST_SEG
          FROM EPCIS_NL_ENDORSE A,
               EPCIS_NL_INSRNC B,
               EPCIS_NL_POLICY E,
               EPCIS_NL_T_CHG_RATE C,
               EPCIS_NL_T_CHG_RATE D,
               (SELECT A.POLICY_NO,
                       A.C_EDR_NO,
                       DECODE(A.SUB_OPENCOVER_NO, NULL, 0, 1) AGREEMENT_TYPE,
                       A.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A.COMMISSION_CHARGE_PROPORTION, 0) +
                       NVL(A.BROKER_CHARGE_PROPORTION, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B.COMMISSION_CHARGE_PROPORTION, 0) +
                       NVL(B.BROKER_CHARGE_PROPORTION, 0)) AS EDR_COMM_PREM,
                       A.TOTAL_ACTUAL_PREMIUM * (NVL(A.CHANGEFEE_RATE, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM * (NVL(B.CHANGEFEE_RATE, 0)) AS EDR_CHANGEFEE_FEE,
                       A.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A.PERFORMANCE_ACTUAL_RATE, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B.PERFORMANCE_ACTUAL_RATE, 0)) AS EDR_PERFORMANCE_ACTUAL_FEE,
                       A.TOTAL_ACTUAL_PREMIUM * (NVL(A.TRANSFORMFEE_RATE, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM * (NVL(B.TRANSFORMFEE_RATE, 0)) AS EDR_TRANSFORMFEE_FEE,
                       A.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A.FULLPERFORMANCE_RATE, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B.FULLPERFORMANCE_RATE, 0)) AS EDR_FULLPERFORMANCE_FEE,
                       A.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A.APPROVABLE_ELSE_CHARGE_RATE, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B.APPROVABLE_ELSE_CHARGE_RATE, 0)) AS EDR_APPROVABLE_ELSE_CHARGE_FEE,
                       A.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A.APPROVABLE_ELSE_CHARGE_RATE2, 0)) -
                       B.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B.APPROVABLE_ELSE_CHARGE_RATE2, 0)) AS EDR_APP_ELSE_CHARGE_FEE2
                  FROM EPCIS_NL_ENDORSE A, EPCIS_NL_ENDORSE B
                 WHERE A.POLICY_NO = B.POLICY_NO
                   AND A.ENDORSEMENT_TIMES = B.ENDORSEMENT_TIMES + 1
                   AND A.ENDORSEMENT_TIMES > 1
                UNION ALL
                SELECT A1.POLICY_NO,
                       A1.C_EDR_NO,
                       DECODE(B1.SUB_OPENCOVER_NO, NULL, 0, 1) AGREEMENT_TYPE,
                       A1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A1.COMMISSION_CHARGE_PROPORTION, 0) +
                       NVL(A1.BROKER_CHARGE_PROPORTION, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B1.COMMISSION_CHARGE_PROPORTION, 0) +
                       NVL(B1.BROKER_CHARGE_PROPORTION, 0)) AS EDR_COMM_PREM,
                       A1.TOTAL_ACTUAL_PREMIUM * (NVL(A1.CHANGEFEE_RATE, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM * (NVL(B1.CHANGEFEE_RATE, 0)) AS EDR_CHANGEFEE_FEE,
                       A1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A1.PERFORMANCE_ACTUAL_RATE, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B1.ORI_PERFORMANCE_ACTUAL_RATE, 0)) AS EDR_PERFORMANCE_ACTUAL_FEE,
                       A1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A1.TRANSFORMFEE_RATE, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B1.TRANSFORMFEE_RATE, 0)) AS EDR_TRANSFORMFEE_FEE,
                       A1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A1.FULLPERFORMANCE_RATE, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B1.FULLPERFORMANCE_RATE, 0)) AS EDR_FULLPERFORMANCE_FEE,
                       A1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A1.APPROVABLE_ELSE_CHARGE_RATE, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B1.ORI_APP_ELSE_CHARGE_RATE, 0)) AS EDR_APPROVABLE_ELSE_CHARGE_FEE,
                       A1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(A1.APPROVABLE_ELSE_CHARGE_RATE2, 0)) -
                       B1.TOTAL_ACTUAL_PREMIUM *
                       (NVL(B1.APPROVABLE_ELSE_CHARGE_RATE2, 0)) AS EDR_APP_ELSE_CHARGE_FEE2
                  FROM EPCIS_NL_ENDORSE A1, EPCIS_NL_POLICY B1
                 WHERE A1.POLICY_NO = B1.POLICY_NO
                   AND A1.ENDORSEMENT_TIMES = 1) T
         WHERE A.PREMIUM_CURRENCY_CODE = C.C_CUR_NO_1
           AND A.POLICY_NO = E.POLICY_NO
           /*and A.POLICY_NO in ( ‘11176001900151672980‘,‘11176001900176570979‘,‘11176001900234509691‘)*/
           AND GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME) <
               (NVL(C.T_EXPD_TM, TIMESTAMP ‘9999-12-31 23:59:59.999‘))
           AND GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME) >=
               C.T_EFFC_TM
           AND C.C_CUR_NO_2 = ‘01‘
           AND A.AMOUNT_CURRENCY_CODE = D.C_CUR_NO_1
           AND GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME) <
               (NVL(D.T_EXPD_TM, TIMESTAMP ‘9999-12-31 23:59:59.999‘))
           AND GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME) >=
               D.T_EFFC_TM
           AND D.C_CUR_NO_2 = ‘01‘
           AND A.PLAN_CODE = B.INSURANCE_CODE
           AND A.DEPARTMENT_CODE NOT LIKE ‘286%‘
           and A.DEPARTMENT_CODE =  ‘21176‘
           and A.plan_code in (‘A13‘, ‘A14‘)
           AND GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME) >=
               TO_DATE(‘20090101‘, ‘YYYYMMDD‘)
           AND TRUNC(GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME)) >=
               TO_DATE(‘20160413‘, ‘YYYYMMDD‘)
           AND TRUNC(GREATEST(A.INSURANCE_BEGIN_TIME, A.UNDERWRITE_TIME)) <
               TO_DATE(‘20160414‘, ‘YYYYMMDD‘)
           AND A.C_EDR_NO = T.C_EDR_NO(+))
          
          
          

123131

标签:

原文地址:http://www.cnblogs.com/zhangwensi/p/5554003.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!