I have two tables, order and products.
The requested table is this...
And the products table is this other...
My intention is to create a procedure that does the following:
- I pass an "idOrder" (it can be several records)
- Makes a Select of all the records with that "idOrder" and starts a loop
In two variables called "totalSale" and "benefit" it adds up...
if(tieneDescuento){ beneficio += (precioConDescuento - precioCoste) totalVenta += precioConDescuento }else{ beneficio += (precioSinDescuento - precioCoste) totalVenta += precioSinDescuento }
In another variable, it adds the total number of items, which increases depending on the "quantity" value in each record.
Finally, and I don't know if this is possible (well, neither is the other), I would like to create a view in which, in a single line, it shows something like
idPedido totalArticulos totalVenta beneficio asd123 36 10564 2954
Thank you very much!!
I finally got it. In case someone finds it useful in the future, here it goes!
//
Finally, the result is the following....