Adding values from a field in a table

1

I have a table where I store the freight values, but when the cart is updated with the freight value, this value is also updated in the table. However, if order # 1111 has 3 items in the cart, it will include in that table the updated freight values. See:

IwouldliketoaddthevaluesofFreight,butbecarefulnottoadd02timesthefreightofthesameorder,whichinthiscaseis16.10.Itriedthisquery,butitdidnotwork:

SELECTSUM(ValorFrete)ASValorTFreteFROMloja_carrinhoWHEREStatusCompras='aguardando'GROUPBYValorFrete

Itreturnsonlyafirstvalueanddoesnotaddvalues.

WhengroupedbyOrder,itreturnsasfollows:

    
asked by anonymous 15.11.2017 / 20:49

1 answer

2

You should first select the items that are repeated, and then add the freight value, example :

SELECT SUM(ValorTFrete) FROM
(
    SELECT DISTINCT NumPedido, ValorTFrete           
    FROM loja_carrinho 
    WHERE StatusCompras = 'aguardando'
) AS t
    
15.11.2017 / 20:53