How to add equal amount of SQL?

0

I have the following query:

SELECT DISTINCT
CTRL_CARGA_PED_VENDA.CtrlCargaNum, ITEM_PED_VENDA.PedVendaNum, 
PRODUTO.ProdCodEstr, PRODUTO.ProdNome, Sum(ITEM_PED_VENDA.ItPedVendaQtd) AS 
QtdItem FROM ITEM_PED_VENDA, CTRL_CARGA_PED_VENDA, PRODUTO
WHERE CTRL_CARGA_PED_VENDA.PedVendaNum = ITEM_PED_VENDA.PedVendaNum
AND ITEM_PED_VENDA.EmpCod = CTRL_CARGA_PED_VENDA.EmpCod
AND ITEM_PED_VENDA.ProdCodEstr = PRODUTO.ProdCodEstr
AND CTRL_CARGA_PED_VENDA.EmpCod = '01'
AND CTRL_CARGA_PED_VENDA.CtrlCargaNum = '0000038'
GROUP BY 
CTRL_CARGA_PED_VENDA.CtrlCargaNum,PRODUTO.ProdNome, ITEM_PED_VENDA.PedVendaNum, PRODUTO.ProdCodEstr, ITEM_PED_VENDA.ItPedVendaQtd

It works perfectly, how do I make it add products that have equal values and leave only a single name?

    
asked by anonymous 11.07.2018 / 22:18

1 answer

0

Hello, you need to leave these two with the same name, after that you just need to do a group by.

select prod_nome, sum(qtde) from teste group by prod_nome

By doing this, besides adding these two desired ones will also add with the sales id '0052887'. If you want to add only the two specifics you need to determine a name equal to only these, so that it is recognized in group by.

    
11.07.2018 / 22:44