SELECT periodo, num_ruc,
       max(flg_desembolso) flg_desembolso,
       max(CASE WHEN order_tasa = 1 and flg_desembolso = 1 then tasa_desembolsada
                WHEN order_tasa = 1 and flg_desembolso = 0 then tasa_piso
                ELSE NULL END
        ) tasa_final
FROM (
    select *,
           row_number() over (
                partition by periodo, num_ruc order by 
                (case when flg_desembolso = 1 and tasa_desembolsada is not null then 0
                           else tasa_piso end
                ) asc
          ) order_tasa
    FROM d_mdl_vpc_disc.UNIVERSO_PRICING_SUNAT
)
GROUP BY periodo, num_ruc

Add a code snippet to your website: www.paste.org