I am using SQL Server 2008
I have a table of sales orders structured like this
PartNo Desc OrderDate OrderQty
60001 widget1 Apr-02-2012 3
60001 widget1 Apr-14-2012 5
60001 widget1 Jun-04-2012 3
60002 widget2 Jan-03-2012 1
60002 widget2 jan-17-2012 1
60002 widget2 aug-04-2012 30
60002 widget2 sep-02-2012 1
60003 widget3 oct-01-2012 4
60003 widget3 oct-04-2012 7
60003 widget3 oct-17-2012 3
60004 widget4 nov-04-2011 8
60004 widget4 nov-05-2011 8
60004 widget4 nov-05-2012 8
60004 widget4 nov-07-2012 7
I want to return a table that is the max of the total per month for each item. It would look like this
PartNo Desc MaxSoldPerMonth Month Year
60001 widget1 8 Apr 2012
60002 widget2 30 Aug 2012
60003 widget3 14 oct 2012
60004 widget4 16 nov 2011
the months are actually in number format(i.e. nov = 11, oct = 10, apr = 4, ect) i just made it this way to make it easy to read. Thanks
This should do it: