I have a small problem with a query, I am trying to add the amounts that exist in my table detalle_ventas, what I want to do is add the quantities that have the same product_id and the same expiration date.
Example:
id_producto | fecha_vencimiento | Total
============|===================|========
1 | 2018-05-03 | 100
------------|-------------------|---------
1 | 2018-12-05 | 150
------------|-------------------|---------
2 | 2017-07-09 | 30
I made this query:
SELECT producto_id, fecha_vencimiento, SUM(cantidad) as cantidad FROM detalle_ventas WHERE fecha_vencimiento = fecha_vencimiento and producto_id = producto_id
But this one adds up all the quantities that are in my database and does not separate them as in the example.
id_producto | fecha_vencimiento | Total
============|===================|========
2 | 2018-05-03 | 280