SELECT A.PERIODO,
           A.TIPO_PO,
           SUM(B.ingreso_total_final),
           COUNT(DISTINCT(A.CDOUNICO)) CANT
    FROM d_mdl_vpc_disc.HM_OBM_IND_BPE_V1 A
    INNER JOIN d_mdl_vpc_disc.MM_OBM_VPC_INGRESOS b
    ON A.cdounico = B.CODUNICO 
    AND A.PERIODO=substr(replace(substr(cast(date_add('month', +1, date_parse(B.PERIODO ,'%Y%m')) as varchar), 1, 10), '-', ''), 1, 6)
    --WHERE TIPO_PO=1
    GROUP BY A.PERIODO,A.TIPO_PO

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