looking for sql query to extract output from the table

learning_grexcel

Active Member
Joined
Jan 29, 2011
Messages
319
Hi,
I have a data with around 2,00,000 rows. The data is similar to the following :
item name >> date >> qty purchased
pen >> 1.03.2011 >> 50
pencil >> 02.03.2011 >> 70
pen >> 05.03.2011 >> 80
pencil >> 04.03.2011 >> 50
etc.
Now I want purchase during the month for particular items like the following :
pen >> 01.03. 2011 >> 50
>> 05.03.2011 >> 80
Total for March >> 130
pencil >> 02.03.2011 >> 70
pen >> 04.03.2011 >> 50
Total for March >> 120

Could you please tell me how to use SQL query to get the desired output?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Access isn't going to give you a "total for March" type of solution under normal circumstances. However, you should be able to group by months and products.

Something like:

Code:
SELECT 
    MyProductID, 
    Sum(MyQtySold) As SumOfQtySold, 
    Format(MyTransactionDate,"yyyy-mm") As MonthOfSale
FROM
   MyTransactionsTable
GROUP BY 
    MyProductID,
    Format(MyTransactionDate,"yyyy-mm")

You must use the real field names - I've made these up for you in absence of the actual details of your table structure.


ξ
 
Upvote 0
Thanks friends
But here the new column "month of sale" doesn't show up day. It shows only month and year. Moreover, it shows only total sum of each items say (1) pen 130 (2) pencil 120.

I want breakdown of each date also along with total sum
Could you please help with this?
 
Upvote 0
Some options are:
  1. create an Access report (you probably can get something halfway decent even with the wizards).
  2. create a daily total as above, then report it in Excel with subtotals.
  3. use a pivot table in Access (not my favorite thing to do but possible).
  4. use a form so you can have subtotal controls for the months.

I imagine there's probably other choices too. I'd probably use Excel for the reporting, or just have two queries - a daily summary and a monthly summary.
 
Upvote 0
Thanks again. I will look into these options. I'm completely new so I have to work hard.

BTW: I don't need actually subtotal. What you have shown is enough for me but I want individual date to be seen in output and the grand total should be shown at the bottom of each item like the following

Pen 1st July 20
Pen 2nd July 30
Pen 3rd July 40
Total 90

Whereas, your code just gives me grand total but it doesn't explain how it came.
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top