Problem with classifying data in SQL

0
SELECT
libro.titulo AS "Titulo Libro",
sum(ventas.cantidad) AS "Cantidad_Comprada"
FROM libro 
left JOIN ventas ON
    libro.id = ventas.id_libro
GROUP BY libro.titulo

I just want to show those elements that have a quantity of sum (sales.quantity) greater than 200, but the WHERE sum(ventas.cantidad)>200 command does not work. Any way to do it?

    
asked by A IRARRAZAVAL 03.10.2017 в 18:56
source

1 answer

1

For this you must use HAVING in the following way:

SELECT
libro.titulo AS "Titulo Libro",
sum(ventas.cantidad) AS "Cantidad_Comprada"
FROM libro 
left JOIN ventas ON
    libro.id = ventas.id_libro
GROUP BY libro.titulo
HAVING sum(ventas.cantidad) > 200 -- Tu condición.
    
answered by 03.10.2017 / 18:58
source