MySQL error 1054 on PhpMyAdmin Localhost

1

I have a proprietary table with customer data and another advance payment that is a table that stores information about the payments of the same. At the time of making a query to obtain and show (if the sum of all the payments of the month exceeds $ 200) this error occurs to me. Who will be so kind to guide me, not with the resolution as such, but rather so that I can understand the concept of the functions and recognize the way of thinking correctly. Thank you.

SELECT nombre, apellido, fecha, SUM(montocobrado) AS TOTAL

FROM estacionamiento.propietario

INNER JOIN estacionamiento.abonoanticipado ON propietario.idPropietario=abonoanticipado.idPropietario

AND TOTAL>=200

GROUP BY propietario.DNI
  

The column "TOTAL" in Where Clause is unknown.

    
asked by Zuckonit 13.12.2018 в 07:16
source

1 answer

2

To filter by a calculated value you should use HAVING like this:

SELECT nombre, apellido, fecha, SUM(montocobrado) AS TOTAL
  FROM estacionamiento.propietario
 INNER JOIN estacionamiento.abonoanticipado ON propietario.idPropietario=abonoanticipado.idPropietario
 GROUP BY propietario.DNI
HAVING TOTAL>=200

You have all the information in the official documentation ( link ).

What the HAVING does is to make a comparison (as would be done in WHERE ) but after filtering the data, that is, it is not used instead of WHERE but next to it (specifically after the WHERE ), to eliminate results that do not validate the condition / is established.

    
answered by 13.12.2018 / 08:55
source