I have a table called products, the products are registered with a single sku and in a column called quantity there are the stocks, I want to add all the records that are in the quantity column but only add those of the same sku, this is my table:
*----*---------*----------*----------*
| id | sku | nombre | cantidad |
*----*---------*----------*----------*
| 1 | 1001 | Refresco | 20 |
*----*---------*----------*----------*
| 2 | 1002 | Papas | 100 |
*----*---------*----------*----------*
| 3 | 1003 | Tortillas| 15 |
*----*---------*----------*----------*
| 4 | 1001 | Refresco | 70 |
*----*---------*----------*----------*
| 5 | 1003 | Tortillas| 30 |
*----*---------*----------*----------*
| 6 | 1001 | Refresco | 20 |
*----*---------*----------*----------*
The code I am applying is:
SELECT SUM(IF(sku=1001, cantidad)) FROM productos;
Send this error:
syntax error near unexpected `if' element