join three tables sql
I have 3 table sales,product_details and order_details. product_details
contain product_id,cost,price order_detail contains product_id, order_id
sales contains date order_id now, I have to minus the sum of cost and
price where date is between __ and __ to show the profit or loss
I have tried this but dont what is the result is showing
SELECT ( SUM(p.price) - SUM(p.cost) )
FROM product_details AS p
LEFT JOIN order_detail AS o
ON o.product_id = p.product_id
JOIN sales AS s
ON s.order_id = o.order_id
WHERE s.[date] = ' 15.08.2013'
No comments:
Post a Comment