I have a set of data such as:
x
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 =)
Advertisement
Answer
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