Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as SQL by registered user vvillacorta ( 2 years ago )
DROP TABLE IF EXISTS d_mdl_vpc_disc.BANCO_PRIN_3
CREATE TABLE d_mdl_vpc_disc.BANCO_PRIN_3
WITH ( format = 'Parquet',
parquet_compression = 'SNAPPY',
partitioned_by = ARRAY['p_periodo'],
external_location= 's3://sagemaker-us-east-1-058528764918/vpc/propension/athena/BANCO_PRIN_3/'
)
AS
(
SELECT periodo_campania, periodo_ejecucion, num_documento,
MAX(CASE WHEN ORDEN = 1 AND banco_desc != 'IBK' AND banco_desc NOT LIKE '%CAJA%' AND banco_desc NOT LIKE '%SIN%' THEN 1 ELSE 0 END) flg_banco_prin_no_ibk,
MAX(CASE WHEN ORDEN = 1 AND banco_desc LIKE '%CAJA%' THEN 1 ELSE 0 END) flg_entidad_prin_caja,
MAX(CASE WHEN ORDEN = 1 AND banco_desc LIKE '%SIN%' THEN 1 ELSE 0 END) flg_sin_colocacion,
MAX(CASE WHEN ORDEN = 1 AND banco_desc = 'BCP' THEN 1 ELSE 0 END) flg_banco_prin_bcp,
MAX(CASE WHEN ORDEN = 1 AND banco_desc = 'MBCO' THEN 1 ELSE 0 END) flg_banco_prin_mbco,
MAX(CASE WHEN ORDEN = 1 AND banco_desc = 'BBVA' THEN 1 ELSE 0 END) flg_banco_prin_bbva,
MAX(CASE WHEN ORDEN = 1 AND banco_desc = 'SCOTIA' THEN 1 ELSE 0 END) flg_banco_prin_scotia,
MAX(CASE WHEN ORDEN = 1 AND banco_desc = 'IBK' THEN 1 ELSE 0 END) flg_banco_prin_ibk,
MAX(CASE WHEN ORDEN = 1 THEN banco_desc ELSE NULL END) entidad_prin_desc,
MAX(CASE WHEN ORDEN = 1 AND banco_desc != 'IBK' THEN saldo_reajustado_amt ELSE 0 END) saldo_entidad_prin_no_ibk,
periodo_ejecucion p_periodo
FROM(
SELECT periodo_campania, periodo_ejecucion, num_documento, banco_desc, saldo_reajustado_amt,
ROW_NUMBER () OVER(PARTITION BY periodo_campania, periodo_ejecucion, num_documento ORDER BY saldo_reajustado_amt DESC) ORDEN
FROM(
SELECT B.periodo_campania, B.periodo_ejecucion, MAX(B.periodo_rcc), B.num_documento, coalesce(P.banco_desc, 'SIN COLOCACION') banco_desc,
sum(coalesce(P.saldo_reajustado_amt,0)) saldo_reajustado_amt
FROM d_mdl_vpc_disc.MM_BASE_RCC_AGENDA B --- UNIVERSO GESTION TELEVENTAS
LEFT JOIN e_perm_aws.T_FACT_VPC_SALDOS_RCC_AJUST_AGG P
ON B.periodo_rcc = P.periodo_val
AND B.cod_sbs_val = P.cod_sbs_val
AND P.tipo_producto_rcc_desc IN ('COL. DIRECTAS','REACTIVA')
AND P.situacion_rcc_desc ='VIGENTE'
AND P.saldo_reajustado_amt > 0
GROUP BY B.periodo_campania, B.periodo_ejecucion, B.num_documento, coalesce(P.banco_desc, 'SIN COLOCACION')
)
)
GROUP BY periodo_campania, periodo_ejecucion, num_documento
)
Revise this Paste