0
Good afternoon Gentlemen, In benefit of my studies I am developing a simple sales system and I am already in the part of the reports.
My doubt is as follows: How to make a select adding up the amount per customer. Next, on the same day a customer can buy several times the same product, I would like to know how to display only once that customer with the total purchase quantity that day.
At the moment my select is like this:
select id_venda as "Cod Venda", pro_nome as "Produto", ven_pro_quantidade as "Quantidade",
nome_cli as "Cliene", ven_dataVenda as "Data" from tblvendas
INNER JOIN tblclientes
ON tblvendas.fk_cliente = tblclientes.idCliente
INNER JOIN tblvendas_produtos
ON tblvendas.id_venda = tblvendas_produtos.fk_id_venda
INNER JOIN tblproduto
ON tblvendas_produtos.fk_id_produto = tblproduto.id_produto
Giving me the following result :
For a better explanation, let’s take the JUICE OF PEAR that made several purchases on the day 11/25/19, need to display the JUICE OF PEAR only once adding up the amount that he bought the day. (PEAR JUICE and other Customers who are in the same condition)
Use the clause
GROUP BY cliente, produto, data
and on the list ofSELECT
use the aggregation functionSUM(quantidade)
. Note that the column will not have much senseCod Venda
.– anonimo
@Mark Alexander: But is that not what the author of the question asked? See the last paragraph of the question. It is true that the client name used as an example was not a good choice.
– anonimo
Did any of the answers solve your problem?
– Lucas Augusto Coelho Lopes