Where am I going wrong in this select?

0

I made the Select below only that it is not adding up by the correct column, where am I going wrong?

In my structure I have the dtConcat2 field and the dtConcat2 field (these dates are different one is for the date of the request and the other is for the date that made the sale) it is adding the column dtConcat2 even I placing in the select that I want the month and year of the dtConcat column

SELECT cat.id, cat.nome_vendedor, MONTH (dtConcat) AS mes, YEAR (dtConcat) AS ano,
SUM( IF( mov.tipo_venda =  'Atacado', mov.total, 0 ) ) AS Atacado
FROM lc_controle AS mov
INNER JOIN vendedor AS cat ON cat.id = mov.vendedor
where mov.exportado = 'Sim'
GROUP BY ano, mes, cat.nome_vendedor 
ORDER BY nome_vendedor, ano, mes
    
asked by anonymous 26.04.2018 / 21:22

1 answer

1

Good afternoon, Robert. Perhaps the problem is that Group By is using the name of the renamed columns and within the same query you have to use the exact From fields that you are using.

If you separate the code by first completing the Inner join, generating a base and then running with group by in a second step works.

But this process will not be as fast as it will split into 2 steps but it works.

    
27.04.2018 / 21:14