Welcome, guest! Login / Register - Why register?
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 ................T1_SALDO_MERCADO_RCC


				CREATE TABLE ................T1_SALDO_MERCADO_RCC
				WITH ( format = 'Parquet', 
					   parquet_compression = 'SNAPPY', 
					   partitioned_by = ARRAY['PERIODO'], 
					   external_location= 's3://.................................../T1_SALDO_MERCADO_RCC/'
					 )
				AS (
				SELECT 
					  cod_sbs_val AS CODSBS,
					  producto_rcc_desc AS PRODUCTO,
					  situacion_rcc_desc AS SITUACION,
					  empresa_cd AS COD_EMPRESA,
					  CASE WHEN coalesce(tipoempresafinanc_desc,'') = 'BANCOS' AND coalesce(estadoempresafinanc_desc,'') ='EN OPERACION' THEN 'BANCOS' ELSE 'CAJAS & FINANC.' END AS TIPO_ENTIDAD,
					  CASE WHEN coalesce(tipoempresafinanc_desc,'') = 'BANCOS' AND coalesce(estadoempresafinanc_desc,'') ='EN OPERACION' THEN nomcortoempresafinanc_desc ELSE 'CAJAS & FINANC.' END AS BANCO,
					  tipo_producto_rcc_desc TIPO_PRODUCTO,
					  SUM(coalesce(saldo_amt, 0)) MTO_SALDO,
				      MAX(coalesce(flg_lin_mercado, 'N')) flg_lin_mercado,
					  MAX(coalesce(condicion_val, 0)) MAX_DIAS_ATRASO,
                      MAX(CASE WHEN coalesce(clasificacion_deudor_cd, '8') in ('0', '8') then 1 else 0 END) FLG_TIENE_CLASIF_NORMAL,
                      MAX(CASE WHEN coalesce(clasificacion_deudor_cd, '8') = '1' then 1 else 0 END) FLG_TIENE_CLASIF_CPP,
                      MAX(CASE WHEN coalesce(clasificacion_deudor_cd, '8') = '2' then 1 else 0 END) FLG_TIENE_CLASIF_DEFICIENTE,
                      MAX(CASE WHEN coalesce(clasificacion_deudor_cd, '8') = '3' then 1 else 0 END) FLG_TIENE_CLASIF_DUDOSO,
                      MAX(CASE WHEN coalesce(clasificacion_deudor_cd, '8') not in ('0','1', '2', '3', '8') then 1 else 0 END) FLG_TIENE_CLASIF_PERDIDA,
                      CASE WHEN cod_sbs_val in (select cod_sbs_val from ......................t_vpc_segmentacion_merc where banca_fin_val = 'BPE' or banca_mes_val = 'BPE') THEN 1 ELSE 0 END FLG_BPE_TIMELINE,
                      CASE WHEN cod_sbs_val in (select cod_sbs_val from ......................t_vpc_segmentacion_merc where banca_fin_val = 'BE' or banca_mes_val = 'BE') THEN 1 ELSE 0 END FLG_BE_TIMELINE,
                      CASE WHEN cod_sbs_val in (select cod_sbs_val from ......................t_vpc_segmentacion_merc where banca_fin_val = 'BC' or banca_mes_val = 'BC') THEN 1 ELSE 0 END FLG_BC_TIMELINE,
                      CASE WHEN cod_sbs_val in (select cod_sbs_val from ......................t_vpc_segmentacion_merc where banca_fin_val = 'MICRO' or banca_mes_val = 'MICRO') THEN 1 ELSE 0 END FLG_MICRO_TIMELINE,
					  periodo_val AS PERIODO
				   FROM ......................T_VPC_FACT_SALDOS_RCC
				   WHERE 1 = 1
				   AND date_parse(cast(periodo_val as varchar),'%Y%m') >= (SELECT date_add('month', -18, date_parse(cast(MAX(periodo_val) as varchar),'%Y%m')) FROM ......................T_VPC_FACT_SALDOS_RCC)
				   AND tipo_producto_rcc_desc IN (
					 'COL. DIRECTAS','REACTIVA','COL. INDIRECTAS','FAE','INMOBILIARIO', 'CREDITOS CASTIGADOS', 'GARANTIA_FAE', 'GARANTIA_REACTIVA', 'GARANTIAS', 'REPROGRAMADOS'
				   )
				   AND 
				   (
					  (
						  flg_lin_mercado = 'S' AND
						  --(
							producto_rcc_desc NOT IN ('OTROS') 
							--OR 
							--(
							--  B.PRODUCTO ='OTROS' AND 
							--  B.DETALLE IN ('FINANCIACION DE PROYECTOS')
							--)
						  --)
					  )					
					  OR tipo_producto_rcc_desc IN ('REACTIVA','FAE','INMOBILIARIO', 'CREDITOS CASTIGADOS', 'GARANTIA_FAE', 'GARANTIA_REACTIVA', 'GARANTIAS', 'REPROGRAMADOS')
				  )
				  GROUP BY 
					  periodo_val,
					  cod_sbs_val,
					  producto_rcc_desc,
					  situacion_rcc_desc,
					  empresa_cd,
					  CASE WHEN coalesce(tipoempresafinanc_desc,'') ='BANCOS' AND coalesce(estadoempresafinanc_desc,'') ='EN OPERACION' THEN 'BANCOS' ELSE 'CAJAS & FINANC.' END,
					  CASE WHEN coalesce(tipoempresafinanc_desc,'') ='BANCOS' AND coalesce(estadoempresafinanc_desc,'') ='EN OPERACION' THEN nomcortoempresafinanc_desc ELSE 'CAJAS & FINANC.' END,
					  tipo_producto_rcc_desc
				  
				)

 

Revise this Paste

Your Name: Code Language: