I have a set of data such as:
Date Product Volume
01-01-2020 A 5
02-01-2020 A 25
03-01-2020 B 20
02-01-2020 B 10
04-01-2020 C 5
02-02-2020 A 30
02-02-2020 B 25
01-02-2020 C 25
01-02-2020 C 40
04-02-2020 C 100
01-03-2020 A 5
01-03-2020 B 0
01-03-2020 A 50
The output would be something like:
Date Product Monthly Volume
01-01-2020 A 30
01-01-2020 B 40
01-01-2020 C 5
01-02-2020 A 30
01-02-2020 B 25
01-02-2020 C 165
01-03-2020 A 55
01-03-2020 B 0
Hopefully that makes sense. Thanks for all the help in advance =)
You can group by month and product, e.g.
SELECT Product, MONTH(Date), Sum(Volume) As Monthly Volume
FROM table
GROUP BY MONTH(Date), Product
Just what I was looking for thanks. Do you know how i would keep the year in the Date column?
You could add another column which reads the year from date, such as
SELECT MONTH(Date), YEAR(Date)
and thenGROUP BY MONTH(Date), YEAR(Date)
thanks for the help, is there no way to keep it in one column in a similar format to: 01-2020, 02-2020, 03-2020 etc
Take a look at concat(column1, column2) w3schools.com/sql/func_sqlserver_concat.asp