Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail 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 ( 9 months ago )
SELECT ZZ.* 
    FROM (
        SELECT periodo_campania, num_ruc, producto, subproducto, tipo_carga,
               CASE WHEN producto in ('NUEVOS APPAS', 'NUEVOS APCONSUMO', 'NUEVOS AP', 'NUEVOS AP SUPER_AGIL') THEN 'NUEVOS AP'
                    WHEN producto in ('ECOSISTEMAS') OR subproducto LIKE '%ECOSISTEMAS%' THEN 'NUEVOS AP'
                    WHEN producto in ('NUEVOS PRE') then 'NUEVOS PRE'
                    ELSE 'X' END campania,
               CASE WHEN producto in ('NUEVOS APPAS', 'NUEVOS APCONSUMO', 'NUEVOS AP', 'NUEVOS AP SUPER_AGIL') THEN 'NUEVOS AP'
                    WHEN producto in ('ECOSISTEMAS') OR subproducto LIKE '%ECOSISTEMAS%' THEN 'ECOSISTEMAS'
                    WHEN producto in ('NUEVOS PRE') then 'NUEVOS PRE'
                    ELSE 'X' END campanha,
               CAST((
                   CASE WHEN oferta like '%Venta%' then Null 
                        WHEN LENGTH(split_part(oferta, 'Oferta 2: ', 2)) > 0 then split_part(oferta, 'Oferta 2: ', 2) 
                        WHEN LENGTH(split_part(oferta, 'Oferta 2:', 2)) > 0 then split_part(oferta, 'Oferta 2:', 2) 
                        WHEN LENGTH(split_part(oferta, '/', 2)) > 0 then split_part(oferta, '/', 2) 
                   ELSE oferta end) AS DOUBLE) oferta,
               plazo,
               bucket,
               canal_tlv,
               tasa,
               CASE WHEN tasa_piso is null and tasa is not null then tasa -0.02 else tasa_piso end tasa_piso,
               ROW_NUMBER() OVER(PARTITION BY periodo_campania, num_ruc, producto ORDER BY tasa DESC) orden_campania,
               periodo_campania p_periodo
        FROM d_mdl_vpc_disc.HM_DESPLIEGUE_CAMPANIAS 
        WHERE producto in ('NUEVOS PRE', 'ECOSISTEMAS', 'NUEVOS APPAS', 'NUEVOS APCONSUMO', 'NUEVOS AP', 'NUEVOS AP SUPER_AGIL')
        and periodo_campania is not null
        and periodo_campania not like ''
        and num_ruc is not null
        and num_ruc not like ''
     ) ZZ
     WHERE ZZ.orden_campania = 1

 

Revise this Paste

Your Name: Code Language: