select sum(totalproduto) as totalM400M800,A.cfop as CFOP_PRODUTO_NOTA, B.cfop as CFOP_CAPA_NOTA, P.participapiscofins, B.participapis, A.cst_pis from produtos_notasaida A inner join lvsaidas B on A.primaria=B.primaria left join cfop P on A.cfop=P.cfop where B.emissao between ('2012-06-01') and ('2012-06-30') and B.CANCELADO='N' and B.EMPRESA=2 and A.cst_pis in ('04','05','06','07','08','09') group by A.cfop, B.cfop, P.PARTICIPAPISCOFINS, B.PARTICIPAPIS, A.cst_pis