SELECT periodo_campania, 
           num_ruc,
           MAX(CASE WHEN lower(gestion_tipo) LIKE '%acepta%' AND lower(gestion_tipo) NOT LIKE '%no%' AND lower(gestion_tipo) NOT LIKE '%visita%' THEN 1 ELSE 0 END) flg_acepta_vpconnect
        FROM d_mdl_vpc_disc.HM_GESTION_VPCONNECT_SQAD C
        WHERE 1 = 1
        and periodo_campania >= '202206'
        AND lower(tipo_campania) LIKE '%adq%'
        AND (
            flg_activo = 1 OR (gestion_tipo IS NOT NULL AND gestion_tipo NOT LIKE '')
        )
        AND NUM_RUC IS NOT NULL
        AND NUM_RUC NOT LIKE ''
        AND NUM_RUC != '.'
        GROUP BY periodo_campania, num_ruc
        ORDER BY periodo_campania DESC, num_ruc

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