Skip to content
Advertisement

How do I sum up each Month of data for each product?

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 =)

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  
1 People found this is helpful
Advertisement