SQL rows to columns plus calculations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Soper
    New Member
    • Jul 2011
    • 1

    SQL rows to columns plus calculations

    Hi there,

    My data looks like this:
    PostCode,Produc t,Month,Sales
    AB10,Product1,2 01106,1212
    AB10,Product2,2 01106,3455
    AB11,Product1,2 01106,3443
    AB11,Product2,2 01106,1344

    I need to transform it to do this:

    Postcode,Produc t,Total3MonthSa les
    AB10,Product1,1 121212
    AB10,Product2,2 34234234
    AB11,Product1,6 78678
    AB11,Product2,2 34234

    So for each postcode, and each product, I need to take the last 3 months of sales and add them together.

    Can anyone help?

    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Use an aggregate sum query grouping by postcode and product and limit by the last three months of data.

    Comment

    Working...