-2
Hello, I have a table that lists purchase quantity of each product, for example, if the buyer makes 3 purchase orders he repeats the orders and quantities. An example of this is the image below:
for example, the soda that has 3 orders of 900, I would like to add this to appear 2700 understand? Would you be able to do this in the select of mysql? Or by PHP?
I would prefer it to be by mysql, to give maintenance later facilitates me. But in PHP I also accept.
My select:
$stid = "SELECT b.id, b.codigo, a.codacesso, a.seqproduto, a.desccompleta, b.quantidade, b.data_vencimento, b.data_atual, b.observacao, b.usuario, b.estado, b.loja, a.medvdiageral, a.comprador, a.preco
FROM master_datas_b a, master_coletores b
WHERE b.tipo_acao IS NULL and a.comprador = :comprador and a.nroempresa = :loja and b.loja = :loja and estado = 'Ativo' and b.codigo = a.codacesso AND b.data_vencimento BETWEEN TO_DATE(:data1,'YYYY-MM-DD') AND TO_DATE(:data2,'YYYY-MM-DD') and b.quantidade > 0 ORDER BY b.data_vencimento, b.codigo ASC";
I believe that the best way is to use the SUM() function with GROUP BY. That is, group your information by request and use the SUM(value) in the select of your query. Maybe it helps: Link I hope I’ve helped!
– Felipe Macedo
You have to make one
GROUP BY
forEAN
and apply aSUM
inQuantidade
. To form an exact answer, it would be interesting if you put yourSELECT
and its structure– Roberto de Campos
put my sql that makes the listing
– Ricardo
The field containing the
EAN
is thecodigo
orcodacesso
?– Roberto de Campos
is the seqproduto guy
– Ricardo
ta giving error :T
– Ricardo
What mistake you’re making?
– Felipe Macedo