I have a products table, with the fields productname, category and cost, of type varchar, varchar and double.
I then have a sales table, with the fields productname, cost, and saledate, of type varchar, double and date.
Lastly, I have a purchases table with the fields purchase, cost and purchasedate, of type varchar, double and date.
I want to calculate the number of sales for certain dates, for certain categories.
I have at the moment this query to show the monthly totals for a year:
SELECT month(saledate), SUM(cost)
FROM sales
GROUP BY month(saledate)
UNION ALL
SELECT month(purchasedate), SUM(cost)
FROM purchases
GROUP BY month(purchasedate)
How could I restrict it to certain categories?
To define certain categories from products, such as food and drink, and only include products in these categories in my calculation?