I am not a complete newbie to SQL or query writing, but this one has got me stumped.
I have a weekly sales gathering database, sales_data, that comes in as such:
location_id, reporting_date, sales
I generate a report that takes the format:
location_id | week_date1 | week_date2 | .....
853 | 12000 | 13444 | .....
989 | 32400 | 36762 | .....
I have been manually building and extending a report that pulls the data by location into date columns like this:
Code:
SELECT location_id,
SUM(if(reporting_date = '2010-11-30',sales, 0)) as '2010-11-30',
SUM(if(reporting_date = '2010-12-07',sales, 0)) as '2010-12-07'
....
FROM sales_data
GROUP BY location_id
The problem is that I don't want to continue writing and extending this report for each week date. Looking for suggestions to make the SUM(IF(...)) generate with some sort of grouping command.
Any assistance or insight on this would be helpful.