How to add equal amount SQL?

Asked

Viewed 566 times

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

Works perfectly, as I do for him to add up the products that have equal values and leave only a single name?

inserir a descrição da imagem aqui

  • 1

    It would not be the case to correct the name that is wrong?

  • I tried not to

  • If you take the name it works but I need the name

  • 1

    puts a MAX or MIN in the name, and takes it out of group by... rsrs also can not have "codprodest" right... and if they are different products, there is no reason to add...

  • 1

    That’s exactly what I thought @Rovannlinhalis

1 answer

0

Hello, you will 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

In doing so, in addition to adding these two desired will also add up to 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 the group by.

  • They are two different products ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.