Skip to content
Advertisement

Query to sum sales totals for X number of months given dates

I would like to make a query that SUMS the total number of sales of each product ID for a group of months (ie. May – August)

I want:

But I am unable to set up the query to do this as I am very new to access (really my first time toying around with it).

This is what my current query spits out:

Essentially, I want one row to sum up all sales for that item for those 4 months (May to August, inclusive of every day in the month). Ignore other columns (price & margin) if necessary.

Any help would be greatly appreciated, I need to have this done by Friday! Have been playing with it for hours but I seem to break something every time I get one step closer. :'(

Here is my current SQL syntax/code (sorry, unaware of the proper term).

This actually currently shows all data for all months and years (I have 2 years worth of data for all products). I just want total sales for each product ID for the four months in one single year (May to August of 2011). PLEASE HELP!

Advertisement

Answer

As this is Access, SQL Fiddle can only be a start.

You need to “quote” the date expressions correctly:

Correction 2015-07-23

I’m terribly sorry for missing that your original data had dates for 2011 and not 2011. I hereby post the corrected SQL for you to test:

This will produce an output from your Access database. For use with SQL Fiddler it will, however, be different:

Sorry for the inconvenience.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement