0
My query SQL is returning multiple Rows with the same id follows:
SELECT distinct (c.nome), c.id, c.email,c.telefone1,c.telefone2,
SUM(a.valor) AS "valorDaCompra",u.id AS "idLoja",u.nome AS "nomeLoja",
SUM(a.qtd_pecas) AS "qtdPecasCompradas", a.data_hora as "dataHora",
c.data_hora as "dataCadastro"
FROM cliente as c
INNER JOIN atendimento AS a
ON a.id_cliente = c.id INNER JOIN usuario AS u
ON a.id_loja = u.id
WHERE a.id_empresa= 843
AND a.id_loja IN (2855)
AND a.venda = true
GROUP BY a.data_hora, c.id,a.id_cliente,u.id,c.data_hora
HAVING SUM(a.valor) >= 2 AND SUM(a.valor) <= 20000
ORDER BY c.id DESC
What happens is this, the 3 option of the a.data_hora issue, the customer when buying on different dates doubles.
– emanuel cavalcante
And yes the user is a store. How can I make the customer not get duplicated?
– emanuel cavalcante
Removes the column (a. time date) of your query. This way the customer stops appearing more than once and the value of your purchase is added disregarding the date of purchase.
– Cleo
Get it here, just put max(a.data_hora) it returns correctly
– emanuel cavalcante
Good!.. just have to keep in mind that this date and time that will appear is the last purchase, but that the value and quantity are all together.
– Cleo
That’s the very intention, vlw Jow
– emanuel cavalcante