--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements.  See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership.  The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License.  You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
SELECT show_name1  as show_name ,show_name2,show_name3,show_name4,show_name5 ,COL1 ,COL2 ,premium_amount_Add ,COL3 ,report_amount ,pure_risk_premium_total ,pure_risk_premium ,direct_claim_cost ,indirect_claim_cost ,settled_loss_total ,important_event_settled_amount ,huge_claim_settled_amount ,small_claim_settled_amount ,object_payed_amount ,direct_fee_amount ,outstanding_claims_reserve_total ,important_event_unsettled_amount ,huge_claim_unsettled_amount ,small_claim_unsettled_amount ,selling_exp ,accrued_charges_adj ,payable_adj ,sale_manage_not ,sale_manage_yes ,fee_control_yes ,achievement_adj ,Recorded_Amount ,Unrecorded_Amount ,operating_exp_total ,branch_bug_mage_exp ,dept_group_bug_mage_exp ,Unrecorded_money ,sec_bug_mage_exp1 ,sec_bug_mage_exp2 ,sec_bug_mage_exp3 ,sec_bug_mage_exp4 ,salesman_exp1 ,salesman_exp2 ,salesman_exp3  ,salesman_exp4  ,commission_fee_total ,fee_wait_discount ,commission_fee1 ,commission_fee2 ,business_perf_total ,salesman_perf1 ,salesman_perf2 ,salesman_perf3 ,whole_not ,whole_yes ,whole_sale_fee ,whole_business_fee ,whole_business_perf ,indirect_commission ,ndoc_selling_sexp ,ndoc_operating_exp ,ndoc_business_perf ,other_alteration ,tax_add_cost ,doc_tax ,ndoc_tax ,policy_cost ,appor_grid_cost ,fix_cost_total_front ,cost_total_midback ,appor_grid_fix_cost ,nper_mp_cost ,asset_de_loss ,amort_rent_front ,appor_dept_group_front ,appor_branch_front ,appor_head_front ,labour_cost_midback ,amort_rent_midback ,daily_cost_midback ,appor_dept_group_midback ,appor_branch_midback ,appor_head_midback  ,difference_fee   ,fix_cost ,Financial_Platform_1 ,Financial_Platform_2 ,Financial_Platform_3 ,Financial_Platform_4 ,Financial_Platform_5 ,Financial_Platform_6 ,orderby FROM (SELECT TF.branch_name AS show_name1 ,TF.dept_group_name AS show_name2 , TF.dept_name AS show_name3,TF.section_name AS show_name4,TF.handler_name AS show_name5        ,premium_amount    AS COL1        ,Premium_Amount/Premium_Amount_Total    AS COL2       ,CASE WHEN premium_amount_ly = 0  or premium_amount_ly is null THEN 1 ELSE  (premium_amount-premium_amount_ly) / premium_amount_ly END AS premium_amount_Add      ,premium365/insured_amount as COL3      ,report_amount / dmt AS report_amount      ,pure_risk_premium_total / dmt AS pure_risk_premium_total      ,pure_risk_premium / dmt AS pure_risk_premium      ,direct_claim_cost / dmt AS direct_claim_cost      ,indirect_claim_cost / dmt AS indirect_claim_cost      ,settled_loss_total / dmt AS settled_loss_total      ,important_event_settled_amount / dmt AS important_event_settled_amount      ,huge_claim_settled_amount / dmt AS huge_claim_settled_amount      ,small_claim_settled_amount / dmt AS small_claim_settled_amount      ,object_payed_amount / dmt AS object_payed_amount      ,direct_fee_amount / dmt AS direct_fee_amount      ,outstanding_claims_reserve_total / dmt AS outstanding_claims_reserve_total      ,important_event_unsettled_amount / dmt AS important_event_unsettled_amount      ,huge_claim_unsettled_amount / dmt AS huge_claim_unsettled_amount      ,small_claim_unsettled_amount / dmt AS small_claim_unsettled_amount        ,(operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee + indirect_commission) / dmt AS selling_exp      ,accrued_charges_adj / dmt AS accrued_charges_adj      ,payable_adj / dmt AS payable_adj      ,sale_manage_not / dmt AS sale_manage_not      ,sale_manage_yes / dmt AS sale_manage_yes      ,fee_control_yes / dmt AS fee_control_yes      ,achievement_adj / dmt AS achievement_adj      ,(payable_adj + fee_control_yes + accrued_charges_adj + achievement_adj + whole_yes + indirect_commission) / dmt AS Recorded_Amount       ,(operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee + indirect_commission - whole_business_perf      - (payable_adj + fee_control_yes + accrued_charges_adj + achievement_adj + whole_yes + indirect_commission))/ dmt AS Unrecorded_Amount       ,operating_exp_total / dmt AS operating_exp_total    ,CASE WHEN '显示比例' = '显示比例' THEN      CASE WHEN '预期赔付率' = '预期赔付率' THEN        (branch_bug_mage_exp+dept_group_bug_mage_exp+sec_bug_mage_exp1+sec_bug_mage_exp2+          sec_bug_mage_exp3+sec_bug_mage_exp4+salesman_exp1+salesman_exp2+salesman_exp3+          salesman_exp4-sale_manage_not-sale_manage_yes-fee_control_yes) / dmt       ELSE          (branch_bug_mage_exp+dept_group_bug_mage_exp+sec_bug_mage_exp1+sec_bug_mage_exp2+          sec_bug_mage_exp3+sec_bug_mage_exp4+salesman_exp1+salesman_exp2+salesman_exp3+          salesman_exp4-sale_manage_not-sale_manage_yes-fee_control_yes) / dmt       END    ELSE      CASE WHEN '预期赔付率' = '预期赔付率' THEN        (branch_bug_mage_exp+dept_group_bug_mage_exp+sec_bug_mage_exp1+sec_bug_mage_exp2+          sec_bug_mage_exp3+sec_bug_mage_exp4+salesman_exp1+salesman_exp2+salesman_exp3+          salesman_exp4-sale_manage_not-sale_manage_yes-fee_control_yes)       ELSE          (branch_bug_mage_exp+dept_group_bug_mage_exp+sec_bug_mage_exp1+sec_bug_mage_exp2+          sec_bug_mage_exp3+sec_bug_mage_exp4+salesman_exp1+salesman_exp2+salesman_exp3+          salesman_exp4-sale_manage_not-sale_manage_yes-fee_control_yes)       END    END    AS Unrecorded_money       ,branch_bug_mage_exp / dmt AS branch_bug_mage_exp        ,dept_group_bug_mage_exp / dmt AS dept_group_bug_mage_exp        ,sec_bug_mage_exp1 / dmt AS sec_bug_mage_exp1      ,sec_bug_mage_exp2 / dmt AS sec_bug_mage_exp2      ,sec_bug_mage_exp3 / dmt AS sec_bug_mage_exp3      ,sec_bug_mage_exp4 / dmt AS sec_bug_mage_exp4      ,salesman_exp1 / dmt AS salesman_exp1      ,salesman_exp2 / dmt AS salesman_exp2      ,salesman_exp3 / dmt AS salesman_exp3      ,salesman_exp4 / dmt AS salesman_exp4      ,commission_fee_total / dmt AS commission_fee_total      ,fee_wait_discount / dmt AS fee_wait_discount      ,commission_fee1 / dmt AS commission_fee1      ,commission_fee2 / dmt AS commission_fee2      ,business_perf_total / dmt AS business_perf_total      ,salesman_perf1 / dmt AS salesman_perf1      ,salesman_perf2 / dmt AS salesman_perf2      ,salesman_perf3 / dmt AS salesman_perf3      ,whole_not / dmt AS whole_not      ,whole_yes / dmt AS whole_yes      ,whole_sale_fee / dmt AS whole_sale_fee      ,whole_business_fee / dmt AS whole_business_fee      ,whole_business_perf / dmt AS whole_business_perf      ,indirect_commission / dmt AS indirect_commission      ,ndoc_selling_sexp / dmt AS ndoc_selling_sexp      ,ndoc_operating_exp / dmt AS ndoc_operating_exp      ,ndoc_business_perf / dmt AS ndoc_business_perf      ,(tax_add_cost + policy_cost + appor_grid_cost) / dmt AS other_alteration      ,tax_add_cost / dmt AS tax_add_cost      ,doc_tax / dmt AS doc_tax      ,(tax_add_cost - doc_tax )/ dmt AS ndoc_tax      ,policy_cost / dmt AS policy_cost      ,appor_grid_cost / dmt AS appor_grid_cost      ,fix_cost_total_front / dmt AS fix_cost_total_front      ,(CASE WHEN '1030101' = '1030101' THEN     cost_total_midback_bgt     ELSE (labour_cost_midback + amort_rent_midback + daily_cost_midback + appor_dept_group_midback      + appor_branch_midback + appor_head_midback)     END) / dmt  AS cost_total_midback      ,appor_grid_fix_cost / dmt AS appor_grid_fix_cost      ,nper_mp_cost / dmt AS nper_mp_cost      ,asset_de_loss / dmt AS asset_de_loss      ,amort_rent_front / dmt AS amort_rent_front      ,appor_dept_group_front / dmt AS appor_dept_group_front      ,appor_branch_front / dmt AS appor_branch_front      ,appor_head_front / dmt AS appor_head_front      ,labour_cost_midback / dmt AS labour_cost_midback      ,amort_rent_midback / dmt AS amort_rent_midback      ,daily_cost_midback / dmt AS daily_cost_midback      ,appor_dept_group_midback / dmt AS appor_dept_group_midback      ,appor_branch_midback / dmt AS appor_branch_midback      ,appor_head_midback / dmt AS appor_head_midback       ,difference_fee / dmt AS difference_fee        ,(CASE WHEN '1030101' = '1030101' THEN       fix_cost_total_front + cost_total_midback_bgt     ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback      + appor_dept_group_midback + appor_branch_midback +appor_head_midback     END) / dmt  AS fix_cost        ,CASE WHEN '显示比例' = '显示金额'      THEN premium_amount - (operating_exp_total + commission_fee_total + business_perf_total + doc_tax + policy_cost) - pure_risk_premium_total + indirect_claim_cost     ELSE ((operating_exp_total + commission_fee_total + business_perf_total+ doc_tax + policy_cost) + pure_risk_premium_total - indirect_claim_cost)/ dmt  END AS Financial_Platform_1      ,(operating_exp_total + commission_fee_total + business_perf_total + doc_tax + policy_cost) / dmt AS Financial_Platform_2      , CASE WHEN '显示比例' = '显示金额'      THEN   premium_amount - pure_risk_premium_total - (operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee + indirect_commission) - (tax_add_cost + policy_cost + appor_grid_cost)     ELSE   (pure_risk_premium_total + (operating_exp_total + commission_fee_total + business_perf_total          + whole_sale_fee + indirect_commission) + (tax_add_cost + policy_cost + appor_grid_cost))/ dmt  END AS Financial_Platform_3        , CASE WHEN '显示比例' = '显示金额'       THEN   premium_amount - pure_risk_premium_total   - (operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee + indirect_commission)   - (tax_add_cost + policy_cost + appor_grid_cost)  - (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback           END) - difference_fee      ELSE   (pure_risk_premium_total + (operating_exp_total + commission_fee_total + business_perf_total          + whole_sale_fee + indirect_commission) + (tax_add_cost + policy_cost + appor_grid_cost)   + (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback           END) + difference_fee )/ dmt END AS Financial_Platform_4      , CASE WHEN '显示比例' = '显示金额'      THEN   (operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee          + indirect_commission) + (tax_add_cost + policy_cost + appor_grid_cost)          + (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback           END) + difference_fee        ELSE   (( operating_exp_total + commission_fee_total + business_perf_total          + whole_sale_fee + indirect_commission) + (tax_add_cost + policy_cost + appor_grid_cost)         + (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback           END) + difference_fee)/ dmt END AS Financial_Platform_5  , CASE WHEN '显示比例' = '显示金额'      THEN   premium_amount - pure_risk_premium_total - report_amount     ELSE   (pure_risk_premium_total + report_amount)/ dmt  END AS Financial_Platform_6  ,(CASE       WHEN '1010100' = '1010100' OR '1010100' = '1010200' THEN      -1*premium_amount      WHEN '1010100' ='1010300' OR '1010100' ='1010400' THEN      -1*(premium_amount - pure_risk_premium_total          - (operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee + indirect_commission)          - (tax_add_cost + policy_cost + appor_grid_cost)          - (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt + difference_fee           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback + difference_fee           END))      WHEN '1010100' ='1010500' OR '1010100' ='1010600' THEN      premium_amount - pure_risk_premium_total          - (operating_exp_total + commission_fee_total + business_perf_total + whole_sale_fee + indirect_commission)          - (tax_add_cost + policy_cost + appor_grid_cost)          - (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt + difference_fee           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback + difference_fee            END)   WHEN '1010100' ='1010700' OR '1010100' ='1010800' THEN    -1*((pure_risk_premium_total + (operating_exp_total + commission_fee_total + business_perf_total          + whole_sale_fee + indirect_commission) + (tax_add_cost + policy_cost + appor_grid_cost)         + (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt + difference_fee           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback + difference_fee           END) ) / dmt) ELSE     (pure_risk_premium_total + (operating_exp_total + commission_fee_total + business_perf_total          + whole_sale_fee + indirect_commission) + (tax_add_cost + policy_cost + appor_grid_cost)         + (CASE WHEN '1030101' = '1030101' THEN             fix_cost_total_front + cost_total_midback_bgt + difference_fee           ELSE fix_cost_total_front+ labour_cost_midback + amort_rent_midback + daily_cost_midback            + appor_dept_group_midback + appor_branch_midback +appor_head_midback + difference_fee           END) ) / dmt END) as orderby FROM (   SELECT      branch_name       ,CASE WHEN 1050103 = 1050101 THEN '合计' ELSE dept_group_name END AS dept_group_name       ,CASE WHEN 1050103 = 1050101 THEN '合计' WHEN 1050103 = 1050102 THEN '合计' ELSE dept_name END AS dept_name       ,CASE WHEN 1050103 = 1050104 THEN section_name WHEN 1050103 = 1050105 THEN section_name ELSE '合计' END AS section_name       ,CASE WHEN 1050103 = 1050105 THEN handler_name ELSE '合计' END AS handler_name          ,CASE    WHEN '预期赔付率' = '预期赔付率' AND '显示比例' = '显示比例' THEN NULLIF(SUM(premium_amount),0)    WHEN '预期赔付率' = '已报告赔付率' AND '显示比例' = '显示比例' THEN NULLIF(SUM(no_tax_earned_premium),0) ELSE 1 END AS dmt     ,CASE    WHEN '预期赔付率' = '预期赔付率' THEN 1 ELSE SUM(no_tax_earned_premium)/SUM(premium_amount) END AS progress          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium_amount) ELSE SUM(no_tax_earned_premium) END   AS premium_amount       ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium365) ELSE SUM(no_tax_earned_premium) END   AS premium365    ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(insured_amount) ELSE SUM(earned_insured_amount) END     AS insured_amount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(report_amount)        ELSE         SUM(report_amount_y)        END AS report_amount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(pure_risk_premium_total) ELSE SUM(reported_pay_total) END  AS pure_risk_premium_total          ,SUM(pure_risk_premium) AS pure_risk_premium          ,SUM(direct_claim_cost) AS direct_claim_cost          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(indirect_claim_cost) ELSE SUM(indirect_fee) END   AS indirect_claim_cost          ,SUM(settled_loss_total) AS settled_loss_total          ,SUM(important_event_settled_amount) AS important_event_settled_amount          ,SUM(huge_claim_settled_amount) AS huge_claim_settled_amount          ,SUM(small_claim_settled_amount) AS small_claim_settled_amount          ,SUM(object_payed_amount) AS object_payed_amount          ,SUM(direct_fee_amount) AS direct_fee_amount    ,SUM(outstanding_claims_reserve_total) AS outstanding_claims_reserve_total    ,SUM(important_event_unsettled_amount) AS important_event_unsettled_amount    ,SUM(huge_claim_unsettled_amount) AS huge_claim_unsettled_amount    ,SUM(small_claim_unsettled_amount) AS small_claim_unsettled_amount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(accrued_charges_adj_cha)        ELSE         SUM(accrued_charges_adj_cha_y)        END AS accrued_charges_adj          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(payable_adj_cha)       ELSE         SUM(payable_adj_cha_y)       END AS payable_adj          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(achievement_adj_cha)        ELSE          SUM(achievement_adj_cha_y)         END AS achievement_adj       ,CASE WHEN '1010101' = '1010102' THEN                CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(operating_exp_total_doc)           ELSE            SUM(operating_exp_total_doc_y)          end       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(operating_exp_total_cha)    ELSE      SUM(operating_exp_total_cha_y)             end       END AS operating_exp_total     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                    SUM(branch_bug_mage_exp_doc)  ELSE   SUM(branch_bug_mage_exp_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(branch_bug_mage_exp_cha)   ELSE     SUM(branch_bug_mage_exp_cha_y)   END       END AS branch_bug_mage_exp     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(dept_group_bug_mage_exp_doc)   ELSE    SUM(dept_group_bug_mage_exp_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(dept_group_bug_mage_exp_cha)   ELSE    SUM(dept_group_bug_mage_exp_cha_y)   END       END AS dept_group_bug_mage_exp     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(sec_bug_mage_exp1_doc)         ELSE   SUM(sec_bug_mage_exp1_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(sec_bug_mage_exp1_cha)    ELSE    SUM(sec_bug_mage_exp1_cha_y)   END       END AS sec_bug_mage_exp1     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(sec_bug_mage_exp2_doc)   ELSE   SUM(sec_bug_mage_exp2_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(sec_bug_mage_exp2_cha)   ELSE    SUM(sec_bug_mage_exp2_cha_y)   END       END AS sec_bug_mage_exp2     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(sec_bug_mage_exp3_doc)  ELSE          SUM(sec_bug_mage_exp3_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(sec_bug_mage_exp3_cha)   ELSE           SUM(sec_bug_mage_exp3_cha_y)   END       END AS sec_bug_mage_exp3     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(sec_bug_mage_exp4_doc)   ELSE            SUM(sec_bug_mage_exp4_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(sec_bug_mage_exp4_cha)  ELSE           SUM(sec_bug_mage_exp4_cha_y)  END       END AS sec_bug_mage_exp4     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(salesman_exp1_doc)  ELSE   SUM(salesman_exp1_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(salesman_exp1_cha)   ELSE           SUM(salesman_exp1_cha_y)   END       END AS salesman_exp1     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(salesman_exp2_doc)   ELSE           SUM(salesman_exp2_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(salesman_exp2_cha)   ELSE            SUM(salesman_exp2_cha_y)   END       END AS salesman_exp2     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(salesman_exp3_doc)  ELSE           SUM(salesman_exp3_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(salesman_exp3_cha)   ELSE           SUM(salesman_exp3_cha_y)   END       END AS salesman_exp3     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(salesman_exp4_doc)  ELSE    SUM(salesman_exp4_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(salesman_exp4_cha)   ELSE            SUM(salesman_exp4_cha_y)   END       END AS salesman_exp4     ,CASE WHEN '1010101' = '1010102' THEN             CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(commission_fee_total_doc)   ELSE     SUM(commission_fee_total_doc_y)   END        ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(commission_fee_total_cha)                       ELSE SUM(commission_fee_total_cha_y)   END       END AS commission_fee_total     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                    SUM(commission_fee1_doc)  ELSE   SUM(commission_fee1_doc_y)  END                 ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(commission_fee1_cha)   ELSE    SUM(commission_fee1_cha_y)   END       END AS commission_fee1     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                     SUM(commission_fee2_doc)  ELSE          SUM(commission_fee2_doc_y)  END              ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(commission_fee2_cha)   ELSE            SUM(commission_fee2_cha_y)   END       END AS commission_fee2     ,case when '1203502' = '1203502' then     CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(business_perf_total_doc)    ELSE      SUM(business_perf_total_doc_y)    END              ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(business_perf_total_cha)    ELSE      SUM(business_perf_total_cha_y)    END         END       else           CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(business_perf_total)    ELSE      SUM(business_perf_total_y)    END       end  AS business_perf_total        ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN                        SUM(salesman_perf1_doc)   ELSE            SUM(salesman_perf1_doc_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(salesman_perf1_cha)    ELSE      SUM(salesman_perf1_cha_y)    END       END AS salesman_perf1     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(salesman_perf2_doc)   ELSE     SUM(salesman_perf2_doc_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(salesman_perf2_cha)    ELSE      SUM(salesman_perf2_cha_y)    END       END AS salesman_perf2     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(salesman_perf3_doc)   ELSE            SUM(salesman_perf3_doc_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(salesman_perf3_cha)    ELSE             SUM(salesman_perf3_cha_y)    END       END AS salesman_perf3     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(ndoc_selling_sexp_doc)   ELSE           SUM(ndoc_selling_sexp_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(ndoc_selling_sexp_cha)   ELSE            SUM(ndoc_selling_sexp_cha_y)   END       END AS ndoc_selling_sexp                   ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(ndoc_operating_exp_doc)    ELSE     SUM(ndoc_operating_exp_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(ndoc_operating_exp_cha)   ELSE            SUM(ndoc_operating_exp_cha_y)   END       END AS ndoc_operating_exp     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(ndoc_business_perf_doc)    ELSE            SUM(ndoc_business_perf_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(ndoc_business_perf_cha)   ELSE            SUM(ndoc_business_perf_cha_y)   END       END AS ndoc_business_perf             ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(cost_total_midback_bgt)       ELSE         SUM(cost_total_midback_bgt_y)       END AS cost_total_midback_bgt     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(tax_add_cost_bgt)   ELSE            SUM(tax_add_cost_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(tax_add_cost_act)   ELSE            SUM(tax_add_cost_act_y)   END       END AS tax_add_cost      ,CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(doc_tax_bgt)   ELSE           SUM(doc_tax_bgt_y)  END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(doc_tax_act)    ELSE             SUM(doc_tax_act_y)    END       END AS doc_tax     ,CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(policy_cost_bgt)  ELSE           SUM(policy_cost_bgt_y)  END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(policy_cost_act)     ELSE             SUM(policy_cost_act_y)    END       END AS policy_cost     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(appor_grid_cost_bgt)   ELSE            SUM(appor_grid_cost_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(appor_grid_cost_act)    ELSE             SUM(appor_grid_cost_act_y)    END       END AS appor_grid_cost     ,CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_grid_fix_cost_bgt)  ELSE    SUM(appor_grid_fix_cost_bgt_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(appor_grid_fix_cost_act)   ELSE     SUM(appor_grid_fix_cost_act_y)   END       END AS appor_grid_fix_cost     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(nper_mp_cost_bgt)   ELSE     SUM(nper_mp_cost_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(nper_mp_cost_act)    ELSE      SUM(nper_mp_cost_act_y)    END       END AS nper_mp_cost     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(asset_de_loss_bgt)   ELSE     SUM(asset_de_loss_bgt_y)    END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(asset_de_loss_act)    ELSE      SUM(asset_de_loss_act_y)    END       END AS asset_de_loss     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(amort_rent_front_bgt)   ELSE            SUM(amort_rent_front_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(amort_rent_front_act)     ELSE      SUM(amort_rent_front_act_y)    END       END AS amort_rent_front     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(labour_cost_midback_bgt)   ELSE     SUM(labour_cost_midback_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(labour_cost_midback_act)   ELSE     SUM(labour_cost_midback_act_y)   END       END AS labour_cost_midback     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(amort_rent_midback_bgt)     ELSE     SUM(amort_rent_midback_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(amort_rent_midback_act)   ELSE     SUM(amort_rent_midback_act_y)   END       END AS amort_rent_midback     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(daily_cost_midback_bgt)   ELSE     SUM(daily_cost_midback_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(daily_cost_midback_act)     ELSE      SUM(daily_cost_midback_act_y)    END       END AS daily_cost_midback            ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(fix_cost_total_front_bgt)   ELSE     SUM(fix_cost_total_front_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN             (SUM(appor_grid_fix_cost_act) + SUM(nper_mp_cost_act) + SUM(asset_de_loss_act)              + SUM(amort_rent_front_act) +CASE                     WHEN '全部分摊' = '不含分摊' THEN                      0                     WHEN '全部分摊' = '全部分摊' THEN                     SUM(appor_dept_group_front_act) +                     SUM(appor_branch_front_act) + SUM(appor_head_front_act)                     WHEN '全部分摊' = '仅含中支公司分摊' THEN                      SUM(appor_dept_group_front_act)                      ELSE                      SUM(appor_dept_group_front_act) +                      SUM(appor_branch_front_act)                    END)    ELSE      (SUM(appor_grid_fix_cost_act_y) + SUM(nper_mp_cost_act_y) + SUM(asset_de_loss_act_y)              + SUM(amort_rent_front_act_y) +CASE                     WHEN '全部分摊' = '不含分摊' THEN                      0                     WHEN '全部分摊' = '全部分摊' THEN                     SUM(appor_dept_group_front_act_y) +                     SUM(appor_branch_front_act_y) + SUM(appor_head_front_act_y)                     WHEN '全部分摊' = '仅含中支公司分摊' THEN                      SUM(appor_dept_group_front_act_y)                      ELSE                      SUM(appor_dept_group_front_act_y) +                      SUM(appor_branch_front_act_y)                    END)     END                END as fix_cost_total_front            ,(CASE WHEN '全部分摊' = '不含分摊' THEN        0        ELSE           CASE WHEN '1030101' = '1030101' THEN              CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(appor_dept_group_front_bgt)        ELSE         SUM(appor_dept_group_front_bgt_y)    END          ELSE              CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(appor_dept_group_front_act)        ELSE         SUM(appor_dept_group_front_act_y)       END    END        END) AS appor_dept_group_front          ,(CASE        WHEN '全部分摊' = '仅含中支公司分摊' THEN 0        WHEN '全部分摊' = '不含分摊' THEN 0        ELSE            CASE WHEN '1030101' = '1030101' THEN               CASE WHEN '预期赔付率' = '预期赔付率' THEN                 SUM(appor_branch_front_bgt)         ELSE          SUM(appor_branch_front_bgt_y)        END   ELSE       CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(appor_branch_front_act)       ELSE         SUM(appor_branch_front_act_y)       END    END     END) AS appor_branch_front          ,(CASE        WHEN '全部分摊' = '全部分摊' THEN            CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                  SUM(appor_head_front_bgt)         ELSE          SUM(appor_head_front_bgt_y)        END     ELSE        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_head_front_act)          ELSE           SUM(appor_head_front_act_y)         END     END        ELSE 0     END) AS appor_head_front          ,(CASE        WHEN '全部分摊' = '不含分摊' THEN 0        ELSE           CASE WHEN '1030101' = '1030101' THEN       CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(appor_dept_group_midback_bgt)       ELSE         SUM(appor_dept_group_midback_bgt_y)       END     ELSE         CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_dept_group_midback_act)         ELSE           SUM(appor_dept_group_midback_act_y)         END     END     END) AS appor_dept_group_midback          ,(CASE        WHEN '全部分摊' = '仅含中支公司分摊' THEN 0        WHEN '全部分摊' = '不含分摊' THEN 0        ELSE            CASE WHEN '1030101' = '1030101' THEN       CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(appor_branch_midback_bgt)                ELSE          SUM(appor_branch_midback_bgt_y)        END     ELSE         CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_branch_midback_act)          ELSE           SUM(appor_branch_midback_act_y)         END     END     END) AS appor_branch_midback          ,(CASE        WHEN '全部分摊' = '全部分摊' THEN        CASE WHEN '1030101' = '1030101' THEN           CASE WHEN '预期赔付率' = '预期赔付率' THEN             SUM(appor_head_midback_bgt)     ELSE      SUM(appor_head_midback_bgt_y)    END         ELSE     CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(appor_head_midback_act)      ELSE       SUM(appor_head_midback_act_y)     END  END        ELSE 0     END) AS appor_head_midback          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(sale_manage_not)       ELSE        SUM(sale_manage_not_y)       END AS sale_manage_not          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(sale_manage_yes)       ELSE         SUM(sale_manage_yes_y)       END AS sale_manage_yes          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(fee_control_yes)        ELSE          SUM(fee_control_yes_y)         END AS fee_control_yes          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(fee_wait_discount)       ELSE         SUM(fee_wait_discount_y)        END AS fee_wait_discount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(whole_yes)        ELSE           SUM(whole_yes_y)        END AS whole_yes           ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(whole_not)       ELSE         SUM(whole_not_y)       END AS whole_not          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(whole_sale_fee)        ELSE SUM(whole_sale_fee_y)       end AS whole_sale_fee          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(whole_business_fee)       ELSE         SUM(whole_business_fee_y)       END AS whole_business_fee          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(whole_business_perf)       ELSE SUM(whole_business_perf_y)        END AS whole_business_perf          ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(indirect_commission_doc)  ELSE      SUM(indirect_commission_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(indirect_commission_sm)  ELSE SUM(indirect_commission_sm_y)         END       END AS indirect_commission              ,CASE WHEN '否' = '是' AND '预算口径' = '核算口径' THEN           CASE WHEN '预期赔付率' = '预期赔付率' THEN             SUM(difference_fee)    ELSE      SUM(difference_fee_y)    END         WHEN '预算口径' = '预算口径'     THEN 0     ELSE 0 END AS difference_fee  FROM DM_CUSTOM_NONAUTO_F t   WHERE 1 = 1     AND (branch_name = '无锡分公司' OR '无锡分公司' = '全部')     AND (dept_group_name = '全部' OR '全部' = '全部')     AND (dept_name = '全部' OR '全部' = '全部')     AND (section_name = '全部' OR '全部' = '全部')     AND (LINE_NAME = '非车险' OR '非车险' = '全部')     AND (product_kind_lv1_name ='全部' OR '全部' = '全部')  AND (product_kind_lv2_name ='全部' OR '全部' = '全部')  AND (in_channel_name ='全部' OR '全部' = '全部')  AND (client_tag_name ='全部' OR '全部' = '全部')     AND  case when '全部' = '是' THEN if_agri_name = '是' when '全部' = '否' THEN if_agri_name = '否' ELSE 1=1 END  AND (public_channel_name = '全部' OR '全部' = '全部')  AND (nonauto_channel1_name = '全部' OR '全部' = '全部')  AND (nonauto_channel2_name = '全部' OR '全部' = '全部')     AND (if_per_credit_name = '全部' OR '全部' = '全部')       AND        CASE          WHEN '原保单起保口径'='原保单起保口径'          THEN inception_period >= '201901-1' AND inception_period <= '201901-4' AND inception_measure = '是'          ELSE signature_period >= '201901-1' AND signature_period <= '201901-4' AND signature_measure = '是'       END     AND period_code = '201901'   GROUP BY branch_name       ,CASE WHEN 1050103 = 1050101 THEN '合计' ELSE dept_group_name END       ,CASE WHEN 1050103 = 1050101 THEN '合计' WHEN 1050103 = 1050102 THEN '合计' ELSE dept_name END       ,CASE WHEN 1050103 = 1050104 THEN section_name WHEN 1050103 = 1050105 THEN section_name ELSE '合计' END       ,CASE WHEN 1050103 = 1050105 THEN handler_name ELSE '合计' END   UNION ALL SELECT      '合计项' AS branch_name,  '合计项' AS dept_group_name,  '合计项' AS dept_name,  '合计项' AS section_name,  '合计项' AS handler_name           ,CASE    WHEN '预期赔付率' = '预期赔付率' AND '显示比例' = '显示比例' THEN NULLIF(SUM(premium_amount),0)    WHEN '预期赔付率' = '已报告赔付率' AND '显示比例' = '显示比例' THEN NULLIF(SUM(no_tax_earned_premium),0) ELSE 1 END AS dmt     ,CASE    WHEN '预期赔付率' = '预期赔付率' THEN 1 ELSE SUM(no_tax_earned_premium)/SUM(premium_amount) END AS progress          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium_amount) ELSE SUM(no_tax_earned_premium) END   AS premium_amount       ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium365) ELSE SUM(no_tax_earned_premium) END   AS premium365    ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(insured_amount) ELSE SUM(earned_insured_amount) END     AS insured_amount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(report_amount)        ELSE         SUM(report_amount_y)        END AS report_amount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(pure_risk_premium_total) ELSE SUM(reported_pay_total) END  AS pure_risk_premium_total          ,SUM(pure_risk_premium) AS pure_risk_premium          ,SUM(direct_claim_cost) AS direct_claim_cost          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(indirect_claim_cost) ELSE SUM(indirect_fee) END   AS indirect_claim_cost          ,SUM(settled_loss_total) AS settled_loss_total          ,SUM(important_event_settled_amount) AS important_event_settled_amount          ,SUM(huge_claim_settled_amount) AS huge_claim_settled_amount          ,SUM(small_claim_settled_amount) AS small_claim_settled_amount          ,SUM(object_payed_amount) AS object_payed_amount          ,SUM(direct_fee_amount) AS direct_fee_amount    ,SUM(outstanding_claims_reserve_total) AS outstanding_claims_reserve_total    ,SUM(important_event_unsettled_amount) AS important_event_unsettled_amount    ,SUM(huge_claim_unsettled_amount) AS huge_claim_unsettled_amount    ,SUM(small_claim_unsettled_amount) AS small_claim_unsettled_amount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(accrued_charges_adj_cha)        ELSE         SUM(accrued_charges_adj_cha_y)        END AS accrued_charges_adj          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(payable_adj_cha)       ELSE         SUM(payable_adj_cha_y)       END AS payable_adj          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(achievement_adj_cha)        ELSE          SUM(achievement_adj_cha_y)         END AS achievement_adj       ,CASE WHEN '1010101' = '1010102' THEN                CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(operating_exp_total_doc)           ELSE            SUM(operating_exp_total_doc_y)          end       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(operating_exp_total_cha)    ELSE      SUM(operating_exp_total_cha_y)             end       END AS operating_exp_total     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                    SUM(branch_bug_mage_exp_doc)  ELSE   SUM(branch_bug_mage_exp_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(branch_bug_mage_exp_cha)   ELSE     SUM(branch_bug_mage_exp_cha_y)   END       END AS branch_bug_mage_exp     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(dept_group_bug_mage_exp_doc)   ELSE    SUM(dept_group_bug_mage_exp_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(dept_group_bug_mage_exp_cha)   ELSE    SUM(dept_group_bug_mage_exp_cha_y)   END       END AS dept_group_bug_mage_exp     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(sec_bug_mage_exp1_doc)         ELSE   SUM(sec_bug_mage_exp1_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(sec_bug_mage_exp1_cha)    ELSE    SUM(sec_bug_mage_exp1_cha_y)   END       END AS sec_bug_mage_exp1     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(sec_bug_mage_exp2_doc)   ELSE   SUM(sec_bug_mage_exp2_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(sec_bug_mage_exp2_cha)   ELSE    SUM(sec_bug_mage_exp2_cha_y)   END       END AS sec_bug_mage_exp2     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(sec_bug_mage_exp3_doc)  ELSE          SUM(sec_bug_mage_exp3_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(sec_bug_mage_exp3_cha)   ELSE           SUM(sec_bug_mage_exp3_cha_y)   END       END AS sec_bug_mage_exp3     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(sec_bug_mage_exp4_doc)   ELSE            SUM(sec_bug_mage_exp4_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(sec_bug_mage_exp4_cha)  ELSE           SUM(sec_bug_mage_exp4_cha_y)  END       END AS sec_bug_mage_exp4     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(salesman_exp1_doc)  ELSE   SUM(salesman_exp1_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(salesman_exp1_cha)   ELSE           SUM(salesman_exp1_cha_y)   END       END AS salesman_exp1     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(salesman_exp2_doc)   ELSE           SUM(salesman_exp2_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(salesman_exp2_cha)   ELSE            SUM(salesman_exp2_cha_y)   END       END AS salesman_exp2     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(salesman_exp3_doc)  ELSE           SUM(salesman_exp3_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(salesman_exp3_cha)   ELSE           SUM(salesman_exp3_cha_y)   END       END AS salesman_exp3     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(salesman_exp4_doc)  ELSE    SUM(salesman_exp4_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(salesman_exp4_cha)   ELSE            SUM(salesman_exp4_cha_y)   END       END AS salesman_exp4     ,CASE WHEN '1010101' = '1010102' THEN             CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(commission_fee_total_doc)   ELSE     SUM(commission_fee_total_doc_y)   END        ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(commission_fee_total_cha)                       ELSE SUM(commission_fee_total_cha_y)   END       END AS commission_fee_total     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                    SUM(commission_fee1_doc)  ELSE   SUM(commission_fee1_doc_y)  END                 ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN    SUM(commission_fee1_cha)   ELSE    SUM(commission_fee1_cha_y)   END       END AS commission_fee1     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                     SUM(commission_fee2_doc)  ELSE          SUM(commission_fee2_doc_y)  END              ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(commission_fee2_cha)   ELSE            SUM(commission_fee2_cha_y)   END       END AS commission_fee2     ,case when '1203502' = '1203502' then     CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(business_perf_total_doc)    ELSE      SUM(business_perf_total_doc_y)    END              ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(business_perf_total_cha)    ELSE      SUM(business_perf_total_cha_y)    END         END       else           CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(business_perf_total)    ELSE      SUM(business_perf_total_y)    END       end  AS business_perf_total        ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN                        SUM(salesman_perf1_doc)   ELSE            SUM(salesman_perf1_doc_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(salesman_perf1_cha)    ELSE      SUM(salesman_perf1_cha_y)    END       END AS salesman_perf1     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(salesman_perf2_doc)   ELSE     SUM(salesman_perf2_doc_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(salesman_perf2_cha)    ELSE      SUM(salesman_perf2_cha_y)    END       END AS salesman_perf2     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(salesman_perf3_doc)   ELSE            SUM(salesman_perf3_doc_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(salesman_perf3_cha)    ELSE             SUM(salesman_perf3_cha_y)    END       END AS salesman_perf3     ,CASE WHEN '1010101' = '1010102' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(ndoc_selling_sexp_doc)   ELSE           SUM(ndoc_selling_sexp_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(ndoc_selling_sexp_cha)   ELSE            SUM(ndoc_selling_sexp_cha_y)   END       END AS ndoc_selling_sexp                   ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(ndoc_operating_exp_doc)    ELSE     SUM(ndoc_operating_exp_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(ndoc_operating_exp_cha)   ELSE            SUM(ndoc_operating_exp_cha_y)   END       END AS ndoc_operating_exp     ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(ndoc_business_perf_doc)    ELSE            SUM(ndoc_business_perf_doc_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(ndoc_business_perf_cha)   ELSE            SUM(ndoc_business_perf_cha_y)   END       END AS ndoc_business_perf            ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(cost_total_midback_bgt)       ELSE         SUM(cost_total_midback_bgt_y)       END AS cost_total_midback_bgt     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(tax_add_cost_bgt)   ELSE            SUM(tax_add_cost_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(tax_add_cost_act)   ELSE            SUM(tax_add_cost_act_y)   END       END AS tax_add_cost      ,CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(doc_tax_bgt)   ELSE           SUM(doc_tax_bgt_y)  END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(doc_tax_act)    ELSE             SUM(doc_tax_act_y)    END       END AS doc_tax     ,CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(policy_cost_bgt)  ELSE           SUM(policy_cost_bgt_y)  END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(policy_cost_act)     ELSE             SUM(policy_cost_act_y)    END       END AS policy_cost     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(appor_grid_cost_bgt)   ELSE            SUM(appor_grid_cost_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(appor_grid_cost_act)    ELSE             SUM(appor_grid_cost_act_y)    END       END AS appor_grid_cost     ,CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_grid_fix_cost_bgt)  ELSE    SUM(appor_grid_fix_cost_bgt_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(appor_grid_fix_cost_act)   ELSE     SUM(appor_grid_fix_cost_act_y)   END       END AS appor_grid_fix_cost     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(nper_mp_cost_bgt)   ELSE     SUM(nper_mp_cost_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(nper_mp_cost_act)    ELSE      SUM(nper_mp_cost_act_y)    END       END AS nper_mp_cost     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(asset_de_loss_bgt)   ELSE     SUM(asset_de_loss_bgt_y)    END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(asset_de_loss_act)    ELSE      SUM(asset_de_loss_act_y)    END       END AS asset_de_loss     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(amort_rent_front_bgt)   ELSE            SUM(amort_rent_front_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(amort_rent_front_act)     ELSE      SUM(amort_rent_front_act_y)    END       END AS amort_rent_front     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(labour_cost_midback_bgt)   ELSE     SUM(labour_cost_midback_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(labour_cost_midback_act)   ELSE     SUM(labour_cost_midback_act_y)   END       END AS labour_cost_midback     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(amort_rent_midback_bgt)     ELSE     SUM(amort_rent_midback_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN     SUM(amort_rent_midback_act)   ELSE     SUM(amort_rent_midback_act_y)   END       END AS amort_rent_midback     ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(daily_cost_midback_bgt)   ELSE     SUM(daily_cost_midback_bgt_y)   END       ELSE           CASE WHEN '预期赔付率' = '预期赔付率' THEN      SUM(daily_cost_midback_act)     ELSE      SUM(daily_cost_midback_act_y)    END       END AS daily_cost_midback            ,CASE WHEN '1030101' = '1030101' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(fix_cost_total_front_bgt)   ELSE     SUM(fix_cost_total_front_bgt_y)   END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN             (SUM(appor_grid_fix_cost_act) + SUM(nper_mp_cost_act) + SUM(asset_de_loss_act)              + SUM(amort_rent_front_act) +CASE                     WHEN '全部分摊' = '不含分摊' THEN                      0                     WHEN '全部分摊' = '全部分摊' THEN                     SUM(appor_dept_group_front_act) +                     SUM(appor_branch_front_act) + SUM(appor_head_front_act)                     WHEN '全部分摊' = '仅含中支公司分摊' THEN                      SUM(appor_dept_group_front_act)                      ELSE                      SUM(appor_dept_group_front_act) +                      SUM(appor_branch_front_act)                    END)    ELSE      (SUM(appor_grid_fix_cost_act_y) + SUM(nper_mp_cost_act_y) + SUM(asset_de_loss_act_y)              + SUM(amort_rent_front_act_y) +CASE                     WHEN '全部分摊' = '不含分摊' THEN                      0                     WHEN '全部分摊' = '全部分摊' THEN                     SUM(appor_dept_group_front_act_y) +                     SUM(appor_branch_front_act_y) + SUM(appor_head_front_act_y)                     WHEN '全部分摊' = '仅含中支公司分摊' THEN                      SUM(appor_dept_group_front_act_y)                      ELSE                      SUM(appor_dept_group_front_act_y) +                      SUM(appor_branch_front_act_y)                    END)     END                END as fix_cost_total_front            ,(CASE WHEN '全部分摊' = '不含分摊' THEN        0        ELSE           CASE WHEN '1030101' = '1030101' THEN              CASE WHEN '预期赔付率' = '预期赔付率' THEN                SUM(appor_dept_group_front_bgt)        ELSE         SUM(appor_dept_group_front_bgt_y)    END          ELSE              CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(appor_dept_group_front_act)        ELSE         SUM(appor_dept_group_front_act_y)       END    END        END) AS appor_dept_group_front          ,(CASE        WHEN '全部分摊' = '仅含中支公司分摊' THEN 0        WHEN '全部分摊' = '不含分摊' THEN 0        ELSE            CASE WHEN '1030101' = '1030101' THEN               CASE WHEN '预期赔付率' = '预期赔付率' THEN                 SUM(appor_branch_front_bgt)         ELSE          SUM(appor_branch_front_bgt_y)        END   ELSE       CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(appor_branch_front_act)       ELSE         SUM(appor_branch_front_act_y)       END    END     END) AS appor_branch_front          ,(CASE        WHEN '全部分摊' = '全部分摊' THEN            CASE WHEN '1030101' = '1030101' THEN        CASE WHEN '预期赔付率' = '预期赔付率' THEN                  SUM(appor_head_front_bgt)         ELSE          SUM(appor_head_front_bgt_y)        END     ELSE        CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_head_front_act)          ELSE           SUM(appor_head_front_act_y)         END     END        ELSE 0     END) AS appor_head_front          ,(CASE        WHEN '全部分摊' = '不含分摊' THEN 0        ELSE           CASE WHEN '1030101' = '1030101' THEN       CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(appor_dept_group_midback_bgt)       ELSE         SUM(appor_dept_group_midback_bgt_y)       END     ELSE         CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_dept_group_midback_act)         ELSE           SUM(appor_dept_group_midback_act_y)         END     END     END) AS appor_dept_group_midback          ,(CASE        WHEN '全部分摊' = '仅含中支公司分摊' THEN 0        WHEN '全部分摊' = '不含分摊' THEN 0        ELSE            CASE WHEN '1030101' = '1030101' THEN       CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(appor_branch_midback_bgt)                ELSE          SUM(appor_branch_midback_bgt_y)        END     ELSE         CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(appor_branch_midback_act)          ELSE           SUM(appor_branch_midback_act_y)         END     END     END) AS appor_branch_midback          ,(CASE        WHEN '全部分摊' = '全部分摊' THEN        CASE WHEN '1030101' = '1030101' THEN           CASE WHEN '预期赔付率' = '预期赔付率' THEN             SUM(appor_head_midback_bgt)     ELSE      SUM(appor_head_midback_bgt_y)    END         ELSE     CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(appor_head_midback_act)      ELSE       SUM(appor_head_midback_act_y)     END  END        ELSE 0     END) AS appor_head_midback          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(sale_manage_not)       ELSE        SUM(sale_manage_not_y)       END AS sale_manage_not          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(sale_manage_yes)       ELSE         SUM(sale_manage_yes_y)       END AS sale_manage_yes          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN          SUM(fee_control_yes)        ELSE          SUM(fee_control_yes_y)         END AS fee_control_yes          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(fee_wait_discount)       ELSE         SUM(fee_wait_discount_y)        END AS fee_wait_discount          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(whole_yes)        ELSE           SUM(whole_yes_y)        END AS whole_yes           ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(whole_not)       ELSE         SUM(whole_not_y)       END AS whole_not          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN        SUM(whole_sale_fee)        ELSE SUM(whole_sale_fee_y)       end AS whole_sale_fee          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(whole_business_fee)       ELSE         SUM(whole_business_fee_y)       END AS whole_business_fee          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN         SUM(whole_business_perf)       ELSE SUM(whole_business_perf_y)        END AS whole_business_perf          ,CASE WHEN '1010101' = '1010102' THEN         CASE WHEN '预期赔付率' = '预期赔付率' THEN            SUM(indirect_commission_doc)  ELSE      SUM(indirect_commission_doc_y)  END       ELSE          CASE WHEN '预期赔付率' = '预期赔付率' THEN           SUM(indirect_commission_sm)  ELSE SUM(indirect_commission_sm_y)         END       END AS indirect_commission      ,CASE WHEN '否' = '是' AND '预算口径' = '核算口径' THEN           CASE WHEN '预期赔付率' = '预期赔付率' THEN             SUM(difference_fee)    ELSE      SUM(difference_fee_y)    END         WHEN '预算口径' = '预算口径'     THEN 0     ELSE 0 END AS difference_fee  FROM DM_CUSTOM_NONAUTO_F t   WHERE 1 = 1     AND (branch_name = '无锡分公司' OR '无锡分公司' = '全部')     AND (dept_group_name = '全部' OR '全部' = '全部')     AND (dept_name = '全部' OR '全部' = '全部')     AND (section_name = '全部' OR '全部' = '全部')     AND (LINE_NAME = '非车险' OR '非车险' = '全部')     AND (product_kind_lv1_name ='全部' OR '全部' = '全部')  AND (product_kind_lv2_name ='全部' OR '全部' = '全部')  AND (in_channel_name ='全部' OR '全部' = '全部')  AND (client_tag_name ='全部' OR '全部' = '全部')     AND  case when '全部' = '是' THEN if_agri_name = '是' when '全部' = '否' THEN if_agri_name = '否' ELSE 1=1 END  AND (public_channel_name = '全部' OR '全部' = '全部')  AND (nonauto_channel1_name = '全部' OR '全部' = '全部')  AND (nonauto_channel2_name = '全部' OR '全部' = '全部')     AND (if_per_credit_name = '全部' OR '全部' = '全部')       AND        CASE          WHEN '原保单起保口径'='原保单起保口径'          THEN inception_period >= '201901-1' AND inception_period <= '201901-4' AND inception_measure = '是'          ELSE signature_period >= '201901-1' AND signature_period <= '201901-4' AND signature_measure = '是'       END     AND period_code = '201901'   GROUP BY 1 ) TF CROSS JOIN (   SELECT      CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium_amount) ELSE SUM(no_tax_earned_premium) END  AS premium_amount_total   FROM DM_CUSTOM_NONAUTO_F t   WHERE 1 = 1     AND (branch_name = '无锡分公司' OR '无锡分公司' = '全部')     AND (dept_group_name = '全部' OR '全部' = '全部')     AND (dept_name = '全部' OR '全部' = '全部')     AND (section_name = '全部' OR '全部' = '全部')     AND (LINE_NAME = '非车险' OR '非车险' = '全部')     AND (product_kind_lv1_name ='全部' OR '全部' = '全部')  AND (product_kind_lv2_name ='全部' OR '全部' = '全部')  AND (in_channel_name ='全部' OR '全部' = '全部')  AND (client_tag_name ='全部' OR '全部' = '全部')     AND  case when '全部' = '是' THEN if_agri_name = '是' when '全部' = '否' THEN if_agri_name = '否' ELSE 1=1 END  AND (public_channel_name = '全部' OR '全部' = '全部')  AND (nonauto_channel1_name = '全部' OR '全部' = '全部')  AND (nonauto_channel2_name = '全部' OR '全部' = '全部')     AND (if_per_credit_name = '全部' OR '全部' = '全部')       AND        CASE          WHEN '原保单起保口径'='原保单起保口径'          THEN inception_period >= '201901-1' AND inception_period <= '201901-4' AND inception_measure = '是'          ELSE signature_period >= '201901-1' AND signature_period <= '201901-4' AND signature_measure = '是'       END     AND period_code = '201901'    ) LEFT JOIN (SELECT      branch_name       ,CASE WHEN 1050103 = 1050101 THEN '合计' ELSE dept_group_name END AS dept_group_name       ,CASE WHEN 1050103 = 1050101 THEN '合计' WHEN 1050103 = 1050102 THEN '合计' ELSE dept_name END AS dept_name       ,CASE WHEN 1050103 = 1050104 THEN section_name WHEN 1050103 = 1050105 THEN section_name ELSE '合计' END AS section_name       ,CASE WHEN 1050103 = 1050105 THEN handler_name ELSE '合计' END AS handler_name          ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium_amount) ELSE SUM(no_tax_earned_premium) END   AS premium_amount_ly     FROM DM_CUSTOM_NONAUTO_F t   WHERE 1 = 1     AND (branch_name = '无锡分公司' OR '无锡分公司' = '全部')     AND (dept_group_name = '全部' OR '全部' = '全部')     AND (dept_name = '全部' OR '全部' = '全部')     AND (section_name = '全部' OR '全部' = '全部')     AND (LINE_NAME = '非车险' OR '非车险' = '全部')     AND (product_kind_lv1_name ='全部' OR '全部' = '全部')  AND (product_kind_lv2_name ='全部' OR '全部' = '全部')  AND (in_channel_name ='全部' OR '全部' = '全部')  AND (client_tag_name ='全部' OR '全部' = '全部')     AND  case when '全部' = '是' THEN if_agri_name = '是' when '全部' = '否' THEN if_agri_name = '否' ELSE 1=1 END  AND (public_channel_name = '全部' OR '全部' = '全部')  AND (nonauto_channel1_name = '全部' OR '全部' = '全部')  AND (nonauto_channel2_name = '全部' OR '全部' = '全部')     AND (if_per_credit_name = '全部' OR '全部' = '全部')       AND        CASE          WHEN '原保单起保口径'='原保单起保口径'          THEN inception_period >= concat(cast(cast(substring('201901-1',1,4) as int)-1 as varchar),substring('201901-1',5,4))    AND inception_period <= concat(cast(cast(substring('201901-4',1,4) as int)-1 as varchar),substring('201901-4',5,4))    AND inception_measure = '是'          ELSE signature_period >= concat(cast(cast(substring('201901-1',1,4) as int)-1 as varchar),substring('201901-1',5,4))    AND signature_period <= concat(cast(cast(substring('201901-4',1,4) as int)-1 as varchar),substring('201901-4',5,4))    AND signature_measure = '是'       END     AND period_code = '201901'   GROUP BY branch_name       ,CASE WHEN 1050103 = 1050101 THEN '合计' ELSE dept_group_name END       ,CASE WHEN 1050103 = 1050101 THEN '合计' WHEN 1050103 = 1050102 THEN '合计' ELSE dept_name END       ,CASE WHEN 1050103 = 1050104 THEN section_name WHEN 1050103 = 1050105 THEN section_name ELSE '合计' END       ,CASE WHEN 1050103 = 1050105 THEN handler_name ELSE '合计' END   UNION ALL SELECT      '合计项' AS branch_name,  '合计项' AS dept_group_name,  '合计项' AS dept_name,  '合计项' AS section_name,  '合计项' AS handler_name           ,CASE WHEN '预期赔付率' = '预期赔付率' THEN SUM(premium_amount) ELSE SUM(no_tax_earned_premium) END   AS premium_amount_ly  FROM DM_CUSTOM_NONAUTO_F t   WHERE 1 = 1     AND (branch_name = '无锡分公司' OR '无锡分公司' = '全部')     AND (dept_group_name = '全部' OR '全部' = '全部')     AND (dept_name = '全部' OR '全部' = '全部')     AND (section_name = '全部' OR '全部' = '全部')     AND (LINE_NAME = '非车险' OR '非车险' = '全部')     AND (product_kind_lv1_name ='全部' OR '全部' = '全部')  AND (product_kind_lv2_name ='全部' OR '全部' = '全部')  AND (in_channel_name ='全部' OR '全部' = '全部')  AND (client_tag_name ='全部' OR '全部' = '全部')     AND  case when '全部' = '是' THEN if_agri_name = '是' when '全部' = '否' THEN if_agri_name = '否' ELSE 1=1 END  AND (public_channel_name = '全部' OR '全部' = '全部')  AND (nonauto_channel1_name = '全部' OR '全部' = '全部')  AND (nonauto_channel2_name = '全部' OR '全部' = '全部')     AND (if_per_credit_name = '全部' OR '全部' = '全部')       AND        CASE          WHEN '原保单起保口径'='原保单起保口径'          THEN inception_period >= concat(cast(cast(substring('201901-1',1,4) as int)-1 as varchar),substring('201901-1',5,4))    AND inception_period <= concat(cast(cast(substring('201901-4',1,4) as int)-1 as varchar),substring('201901-4',5,4))    AND inception_measure = '是'          ELSE signature_period >= concat(cast(cast(substring('201901-1',1,4) as int)-1 as varchar),substring('201901-1',5,4))    AND signature_period <= concat(cast(cast(substring('201901-4',1,4) as int)-1 as varchar),substring('201901-4',5,4))    AND signature_measure = '是'       END     AND period_code = '201901'   GROUP BY 1) BF   ON TF.branch_name = BF.branch_name   AND TF.dept_group_name = BF.dept_group_name   AND TF.dept_name = BF.dept_name   AND TF.section_name = BF.section_name   AND TF.handler_name = BF.handler_name ) TD ORDER BY CASE WHEN show_name1 = '合计项' THEN 1  ELSE 2 END,orderby limit 1000000
