List:General Discussion« Previous MessageNext Message »
From:Daniel Bowett Date:October 26 2005 1:46pm
Subject: Sum of Sales
View as plain text  
I am unsure how to write this query, can someone help?

I have two tables.

One has a list of retailers (tbl_retailer):

retailerid
name
postcode

e.g.

1   Sprocket Supplies   CH23 4PY

The other has the sales by month for each retailer:

retailerid
month_2	
sales

e.g.

1   2004-01   100
1   2004-02   400
1   2004-03   300
1   2004-04   200
1   2004-05   300


What I need is a way to output a list of each retailer with two columns 
at the end being sales this year to date and the equivalent sales for 
the previous year.

So the columns would be:

name	this_years_sales_to_date	last_years_sales_to_date

Total sales for ever would be a simple GROUP BY query with a sum on the 
sales - but I cant see how I am going to get this info. Do I need to use 
nested queries?

Regards,

Dan.


Thread
Sum of SalesDaniel Bowett26 Oct
  • Re: Sum of SalesPeter Brawley26 Oct
    • Re: Sum of SalesDaniel Bowett26 Oct
      • Re: Sum of SalesMichael Stassen26 Oct
        • Re: Sum of SalesDaniel Bowett26 Oct
          • Re: Sum of SalesSGreen26 Oct
          • Re: Sum of SalesPeter Brawley26 Oct
          • Re: Sum of SalesMichael Stassen26 Oct
            • Re: Sum of SalesDaniel Bowett27 Oct
  • Re: Sum of SalesSGreen26 Oct