How can I groupBy product_id a query on transactions
but I need the products with options to be shown separately.
For example in the table transactions
if I have:
ProductID Quantity Price
1 1 10
1 1 10
1 1 15 (in transaction_options this has option green(price 2,5),yellow(price 2,5))
1 1 15 (in transaction_options this has option red(price 2,5),blue(price 2,5))
I want the result to be:
ProductID Quantity Price
1 2 10
1 1 15 (this has option red(price 2,5),blue(price 2,5))
1 1 15 (this has option green(price 2,5),yellow(price 2,5))
The problem is that they all have the same product_id, and the price can be the same but for different options.
This are the tables structure:
products
with id,name,price
options
with id,name,price
transactions
with id,product_id,quantity,price
transaction_options
with id,transaction_id,option_id
(association table between transactions
and options
In transactions
I insert the price
calculated based on option (if there are any) :
product.price+[option.price] = transaction.price