I have three tables products, sales and costs.
The sales and products table each have a costs field of type decimal and a date field of type date.
Additionally, the sales table has a productname field, which is matched to a productname field in the products tables.
The products table also has a category field.
I want to select all sales and all purchases for each month, and display them in separate columns grouped by month, up until the current year.
Something like the following
Sales Purchases
January 100 50
Febuary 100 50
March 100 50
April 100 50
May 100 50
June 100 50
July 30 50
The purchases table is not related to any other table.
However, the sales table productname field only contains products that exist in the products.productname.
I want to add on to the end of my query
WHERE sales.productname=products.productname AND category='Food'
I am unsure how to return multiple columns, sum them for each month, and then group them by month.
I asked something similar here, and took a solution however it returned sales and purchases together in one column.
How would I keep them as separate columns?