Dan, >...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? You don't need nested queries. It's a crosstab or pivot table query. The trick is to sum into one column per desired year, scope the sums on month-to-date, and group by retailer, eg: SELECT r.name, SUM(IF(LEFT(month_2,4)='2004',sales, '')) AS '2004 Sales', SUM(IF(LEFT(month_2,4)='2005',sales, '')) AS '2005 Sales' FROM tbl_retailer AS r INNER JOIN tbl_sales AS s USING (retailerid) WHERE SUBSTRING(month_2,6,2)<MONTH(NOW()) GROUP BY r.name; PB ----- Daniel Bowett wrote: I am unsure how to write this query, can someone help? |
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.361 / Virus Database: 267.12.5/149 - Release Date: 10/25/2005
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]