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 Plain Text by registered user vvillacorta ( 3 years ago )
DROP TABLE IF EXISTS ......................T2_SALDO_MERCADO_SF_REAJUSTADO
CREATE TABLE ......................T2_SALDO_MERCADO_SF_REAJUSTADO
WITH ( format = 'Parquet',
parquet_compression = 'SNAPPY',
partitioned_by = ARRAY['PERIODO'],
external_location= 's3://........................................................./T2_SALDO_MERCADO_SF_REAJUSTADO/'
)
AS (
SELECT A.CODSBS,
A.PRODUCTO,
A.SITUACION,
A.COD_EMPRESA,
A.TIPO_ENTIDAD,
A.BANCO,
A.TIPO_PRODUCTO,
A.FLG_LIN_MERCADO,
A.MTO_SALDO as MTOSALDO_SIN_AJUSTE,
A.MAX_DIAS_ATRASO,
A.FLG_BPE_TIMELINE,
A.FLG_BC_TIMELINE,
A.FLG_BE_TIMELINE,
A.FLG_MICRO_TIMELINE,
A.FLG_TIENE_CLASIF_NORMAL,
A.FLG_TIENE_CLASIF_CPP,
A.FLG_TIENE_CLASIF_DEFICIENTE,
A.FLG_TIENE_CLASIF_DUDOSO,
A.FLG_TIENE_CLASIF_PERDIDA,
B.MTOSALDO AS SALDO_REACTIVA,
C.MTOSALDO AS SALDO_FAE,
CASE WHEN coalesce(A.MTO_SALDO,0) - coalesce(B.MTOSALDO,0) - coalesce(C.MTOSALDO,0) >= 0
THEN coalesce(A.MTO_SALDO,0)- coalesce(B.MTOSALDO,0) - coalesce(C.MTOSALDO,0) ELSE 0 END AS MTOSALDO_REAJUSTADO,
A.PERIODO
FROM ......................T1_SALDO_MERCADO_RCC A
LEFT JOIN
(
SELECT PERIODO, CODSBS, COD_EMPRESA, SITUACION,
SUM(MTO_SALDO) AS MTOSALDO
FROM ......................T1_SALDO_MERCADO_RCC
WHERE TIPO_PRODUCTO='REACTIVA'
GROUP BY PERIODO, CODSBS, COD_EMPRESA, SITUACION
) B
ON A.PERIODO = B.PERIODO
AND A.CODSBS = B.CODSBS
AND A.COD_EMPRESA = B.COD_EMPRESA
AND A.SITUACION = B.SITUACION
AND A.PRODUCTO='PRESTAMOS'
LEFT JOIN
(
SELECT PERIODO, CODSBS, COD_EMPRESA, SITUACION,
SUM(MTO_SALDO) AS MTOSALDO
FROM ......................T1_SALDO_MERCADO_RCC
WHERE TIPO_PRODUCTO='FAE'
GROUP BY PERIODO, CODSBS, COD_EMPRESA, SITUACION
) C
ON A.PERIODO = C.PERIODO
AND A.CODSBS = C.CODSBS
AND A.COD_EMPRESA = C.COD_EMPRESA
AND A.SITUACION = C.SITUACION
AND A.PRODUCTO='PRESTAMOS'
)
Revise this Paste