select SUM(A.BASEPIS),A.CFOP, P.PARTICIPAPISCOFINS, P.NAT_BC_CRED from produtos_notaentrada A inner join lventradas B on A.primaria=B.primaria inner join CFOP P on A.CFOP=P.CFOP where A.CST_PIS in ('50','51','52','53','54','55','56','60','66') and B.entrada between ('2012-06-01') and ('2012-06-30') and B.cancelado='N' group by A.CFOP, P.PARTICIPAPISCOFINS, P.NAT_BC_CRED