the problem is thisEste es el problema a resolver:
I have a table where I registerTengo una tabla, en la cual se registran desde 1 hasta 5 different productsdiferentes productos, a product can be both in the fieldpero no hay un control de orden al registrar los productos, en un registro un producto puede estar en el campo product_1 in they en otro registro puede estar en el campo product_5, what I need is to add the quantity of each product and group it by id.esta es la estructura de la tabla:
This is the structure of the table. *-----------------++ |ID | |DATE | |ID_PRODUCT_1 | |QUANTITY_PRODUCT_1| |ID_PRODUCT_2 | |QUANTITY_PRODUCT_2| |ID_PRODUCT_3 | |QUANTITY_PRODUCT_3| |ID_PRODUCT_4 | |QUANTITY_PRODUCT_4| |ID_PRODUCT_5 | |QUANTITY_PRODUCT_5| +------------------+
*-----------------++
|ID |
|DATE |
|ID_PRODUCT_1 |
|QUANTITY_PRODUCT_1|
|ID_PRODUCT_2 |
|QUANTITY_PRODUCT_2|
|ID_PRODUCT_3 |
|QUANTITY_PRODUCT_3|
|ID_PRODUCT_4 |
|QUANTITY_PRODUCT_4|
|ID_PRODUCT_5 |
|QUANTITY_PRODUCT_5|
+------------------+
And these are some example records, what I need is to add the quantity of the product with id = 1001, although this id exists in the other records, but in a different fieldEstos son unos registros de ejemplo, and also sum the other products respectively.de lo que acabo de explicar:
so that in the end this Is the resultLo que necesito es sumar la cantidad de cada producto, sin importar en qué campo haya sido registrado, y al final este sería el resultado:
+--------------------------------+
|SUM(PRODUCT WITH ID 1001) = 2600|
|SUM(PRODUCT WITH ID 1002) = 2000|
|SUM(PRODUCT WITH ID 1003) = 2000|
+--------------------------------+
SUM(PRODUCT WITH ID 1001) = 2600 SUM(PRODUCT WITH ID 1002) = 2000 SUM(PRODUCT WITH ID 1003) = 2000Muchas gracias.