I have a mysql query that is trying to combine the following tables:
TABLE: orders_products
products_id
orders_id
products_quantity
products_price
TABLE: products
products_id
products_model
I want a query that returns the total number of sales, the total sales value for each product_id, and the product_model for each product in the orders_products table. This is the best I’ve come up with so far and it just adds everything into the same bucket:
SELECT
SUM( op.products_quantity ) AS num_sold
,SUM( op.final_price * op.products_quantity )
,p.products_model
FROM orders_products AS op
JOIN products AS p
WHERE p.products_id = op.products_id
Add a
group by p.products_idafter yourwhereand you will be good