Вы находитесь на странице: 1из 2

SELECT pol.

pol_id,
pol.pol_pfx || ' ' || pol.gcic_pol_seq_num || ' ' ||pol.gcic_pol_mdl pol_num,
to_char(pol_eff_dt,'YYYYMMDD') pol_eff_dt,
to_char(pol_exp_dt,'YYYYMMDD') pol_exp_dt,
rtrim(ins.insur_nm) insur_nm,
decode(ins.insur_addr_1,NULL,rtrim(ins.insur_addr_2),rtrim(ins.insur_addr_1))
insur_addr,
rtrim(ins.insur_city) insur_city,
ins.insur_st insur_st,
replace(ins.insur_zip, '-') insur_zip,
decode(trn.tran_typ_cd, '01', 'NB', '02', 'RN', trn.tran_typ_cd) tran_typ_cd,
bss.class_cd class_cd,
sum(nvl(bss.actl_prem,0)) package_prem,
sum(decode(cov.liab_cov_typ_cd,NULL, nvl(bss.actl_prem,0),0) )property_prem,
sum(nvl(bss.actl_prem,0) + nvl(bss.comm_pct,0)) gross_prem,
sum(nvl(bss.actl_prem,0) - nvl(bss.comm_pct,0) ) net_prem,
max(nvl(lim.lim_amt,0) ) lim_amt,
max(nvl(ded.amt,0)) deduc_amt,
sum(nvl(bss.expos_amt, 0)) expos_amt
FROM cen_pr_bp_lim lim,
cen_pr_bp_bldng_deduc ded,
cen_pr_bp_rtg_basis bss,
cen_pr_bp_pol_cov cov,
aic_pr_gb_tran_dt_pol trn,
aic_pr_gb_pol_div_role rol,
aic_pr_gb_frst_nm_insur ins,
aic_pr_gb_pol pol
WHERE ins.pol_id = pol.pol_id
AND rol.pol_id = pol.pol_id
AND rol.div_role_cd = 'PW'
AND trn.pol_id = pol.pol_id
AND trn.tran_num = pol.tran_num
--
AND cov.pol_id = pol.pol_id
AND cov.tran_exp_dt = pol.pol_exp_dt

AND cov.pol_id=bss.pol_id(+)
AND cov.pol_cov_id = bss.pol_cov_id(+)
AND cov.loc_bldng_id=bss.loc_bldng_id(+)
--
AND cov.pol_id=ded.pol_id(+)
AND cov.loc_bldng_id=ded.loc_bldng_id(+)
--
AND cov.pol_id=lim.pol_id(+)
AND cov.pol_cov_id = lim.pol_cov_id(+)
--
-- AND cust_acct_num in (934335 /,932133,59165/)
GROUP BY pol.pol_id,
pol.pol_pfx || ' ' || pol.gcic_pol_seq_num || ' ' ||
pol.gcic_pol_mdl,
to_char(pol_eff_dt,'YYYYMMDD'),
to_char(pol_exp_dt,'YYYYMMDD'),
rtrim(ins.insur_nm),
decode(ins.insur_addr_1,NULL,rtrim(ins.insur_addr_2),rtrim(ins.insur_addr_1)),
rtrim(ins.insur_city),
ins.insur_st,
replace(ins.insur_zip, '-'),
decode(trn.tran_typ_cd, '01', 'NB', '02', 'RN', trn.tran_typ_cd),
bss.class_cd
=================================
SELECT a.POL_ID,
a.CUST_ACCT_NUM,
a.KIND_OF_POL_CD,
a.POL_EFF_DT,
a.POL_EXP_DT,
a.INSUR_NM,
a.INSUR_ADDR_1,
a.INSUR_CITY,
a.INSUR_ST,
a.INSUR_ZIP,
a.TRAN_TYP_CD,
a.CLASS_CD,
(a.GrassPackagePrem),
(a.GrassPropertyPrem),
(a.DCCovGrassPrem),
(a.DCCovNetPrem),
(a.PolTotInsVal),
(a.COMM_PCT) COMM_PCT,
LAG(a.POL_ID, 1) OVER(PARTITION BY a.CUST_ACCT_NUM ORDER BY a.POL_ID) PrevPolId
FROM (SELECT POL.POL_ID,
POL.CUST_ACCT_NUM,
POL.KIND_OF_POL_CD,
POL.POL_EFF_DT,
POL.POL_EXP_DT,
INSUR.INSUR_NM,
INSUR.INSUR_ADDR_1,
RTRIM(INSUR.INSUR_CITY) INSUR_CITY,
INSUR.INSUR_ST,
REPLACE(INSUR.INSUR_ZIP,'-') INSUR_ZIP,
DECODE(TRAN.TRAN_TYP_CD,'01','NB','02','RN',TRAN.TRAN_TYP_CD) TRAN_TYP_CD,
RB.CLASS_CD,
NVL(RB.ACTL_PREM, 0) GrassPackagePrem,
(CASE WHEN COV.LIAB_COV_TYP_CD IS NULL THEN
NVL(RB.ACTL_PREM, 0)ELSE 0 END) GrassPropertyPrem,
NVL(RB.ACTL_PREM, 0) + NVL(RB.COMM_PCT, 0) DCCovGrassPrem,
NVL(RB.ACTL_PREM, 0) - NVL(RB.COMM_PCT, 0) DCCovNetPrem,
NVL(RB.EXPOS_AMT, 0) PolTotInsVal,
NVL(RB.COMM_PCT, 0) COMM_PCT
FROM CEN_PR_BP_RTG_BASIS RB,
CEN_PR_BP_POL_COV COV,
AIC_PR_GB_POL_DIV_ROLE ROLE,
AIC_PR_GB_FRST_NM_INSUR INSUR,
AIC_PR_GB_TRAN_DT_POL TRAN,
AIC_PR_GB_POL POL
WHERE COV.POL_ID = RB.POL_ID
AND COV.LOC_BLDNG_ID = RB.LOC_BLDNG_ID
AND COV.BP_COV_GCIC_COV_CD = RB.BP_COV_GCIC_COV_CD
AND COV.POL_ID = POL.POL_ID
AND INSUR.POL_ID = POL.POL_ID
AND TRAN.POL_ID = POL.POL_ID
AND TRAN.TRAN_NUM = POL.TRAN_NUM
AND ROLE.POL_ID = POL.POL_ID
AND ROLE.TRAN_EXP_DT = POL.POL_EXP_DT
AND ROLE.TRAN_EFF_DT <> ROLE.TRAN_EXP_DT
AND ROLE.DIV_ROLE_CD = 'UN') a

Вам также может понравиться