I am doing a query to calculate the balance and after calculated I want it to only bring the products whose balance is equal to 0
so I tried to assign the total value using AS
only when I went to make the condition in WHERE
he did not recognize
SELECT mov.Codigo, (
SUM( IF( (
mov.Tipo = "2"
), mov.Quantidade, 0 ) ) + SUM( IF( (
mov.Tipo = "5"
), mov.Quantidade, 0 ) ) + SUM( IF( (
mov.Tipo = "7"
), mov.Quantidade, 0 ) ) - SUM( IF( (
mov.Tipo = "3"
OR mov.Tipo = "4"
OR mov.Tipo = "6"
), mov.Quantidade, 0 ) ) + (
SELECT SUM( quantidade_balanco )
FROM balancos
WHERE produto = mov.Codigo )
) AS total
FROM movimentacao AS mov WHERE total=0
GROUP BY mov.Codigo
1054 - Unknown column 'total' in 'where clause'