Hello I have a question about how to make a query in sql to add the total time it takes to produce the product.
The diagram is a table of products that has sub-products, the design is an NN relationship with itself so I made an auxiliary table to store what would be the id of the parent product with the id of the child product . I keep that relation in the product_x_productos table with the number of child products in the relationship.
These would be the tables
productos(PK idproducto, tiempo_produccion INT)
productos_x_productos(PK idproducto_padre (FK productos.idproducto), PK idproducto_hijo (FK productos.idproducto), cantidad INT)
A product has a time that takes to be manufactured, this product in turn can be composed of several products that also have their time of manufacture and in addition to the amount of each sub-product of the same type.
I would like to know how to make the query that sum total time to manufacture the product what would be total_time = total_time + (total_time_child) * amount (that for each sub-product you have)
I do not know if it could be done in a single consultation, it would be the best, but if you can not if someone could guide me on how to do it in an SP. The database engine is MYSQL.