joined:Feb 9, 2010
Hello, I have this query:
SELECT order_details.product_code AS 'SKU', SUM(order_details.amount), SUM(order_details.price) AS 'Selling Price'
FROM order_details, orders
WHERE (order_details.product_code LIKE 'SM%' OR order_details.product_code LIKE 'AZ1%')
AND orders.order_id = order_details.order_id
GROUP BY substring(order_details.product_code, 1, 9)
ORDER BY order_details.product_code, order_details.amount DESC;
which works. However, the LIKE parts are haphazard. So, I've added manufacture.id to the products table (not in this query) and have to change the LIKE parameters with something like:
WHERE (order_details.product_code = products.product_code AND products.mfr = 'mazda')
I've got brain freeze on this. Of course I have to add products.mfr to the select line. I suppose I have to join the mfr id to the order_details... but I'm stuck.