Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Queries

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-29-2006, 11:55 AM
PercyPercy PercyPercy is offline
Registered User
 
Join Date: Jun 2006
Posts: 9
PercyPercy is on a distinguished road
Calculating Totals per Item

For some reason I can't write the proper query to get a simple total from a single table. Here is the basic table design:

Transaction ID___Product ID___ Transaction Date____Transaction Quantity
1______________Product A____6/12/2006__________200
2______________Product B____6/12/2006__________500
3______________Product C____6/14/2006__________100
4______________Product B____6/15/2006__________200
5______________Product C____6/16/2006__________300
6______________Product A____6/17/2006__________500


I'm trying to get the total transactions quantity for each product so that I could end up with a form or a report that would show:

Product ID_____ Transaction Quantity Total
Product A______700
Product B______700
Product C______400


... and so on for each item.

What would actually be entered in the query? I'm assuming I would have four columns in the query:

transaction id____product number____transaction qty____expression

Then I would use the SUM feature so the "group by" row appears.

Then I would build the expression above in an expression column. If that's correct, could you give me the expression typed "exactly" as you think it would appear? I'm getting syntax errors when I'm trying it.

And then, once I have the expression built, what should be the "group by" selection under each of the columns?

Sorry for being so ignorant. The rest of my data base works great... but I'm just not getting this one thing!

Thanks anyone who can help me!
Reply With Quote
Sponsored Links
  #2  
Old 06-29-2006, 12:06 PM
Matt Greatorex's Avatar
Matt Greatorex Matt Greatorex is offline
Registered User
 
Join Date: Jun 2005
Location: Ontario, Canada (formerly Cardiff, Wales.)
Posts: 1,019
Matt Greatorex is on a distinguished road
You're trying to use the group by clause to include a field where, by the looks of it, all the values are unique (transaction id). You probably only want something like

SELECT [Product ID], Sum([Transaction Quantity])
FROM tablename
GROUP BY [Product ID];

Last edited by Matt Greatorex; 06-29-2006 at 12:13 PM..
Reply With Quote
  #3  
Old 06-29-2006, 12:20 PM
PercyPercy PercyPercy is offline
Registered User
 
Join Date: Jun 2006
Posts: 9
PercyPercy is on a distinguished road
I'm such a novice, I'm not quite understanding what you mean by:

SELECT [Product ID], Sum([Transaction Quantity])
FROM tablename
GROUP BY [Product ID];

So do I use the SUM function -- so the "group by" appears on the "Total" row?

I guess I just don't know what to type -- and where it should go!

I don't know if you can give me a step-by-step instruction or not. Any help is appreciated though...
Reply With Quote
  #4  
Old 06-29-2006, 02:24 PM
RV RV is offline
Registered User
 
Join Date: Feb 2002
Location: UK
Posts: 1,115
RV is on a distinguished road
Quote:
So do I use the SUM function -- so the "group by" appears on the "Total" row?
You need to use a GROUP BY whenever you're using aggregate functions, such as SUM, MIN, MAX.
GROUP BY groups your calculations.
So, as per Matt's solution, you'll end up having exactly what you need.

Read up a bit in Access Help on GROUP BY and aggregate functions.

RV
Reply With Quote
  #5  
Old 07-03-2006, 03:55 PM
B4Geyer B4Geyer is offline
Registered User
 
Join Date: Jun 2006
Posts: 11
B4Geyer is an unknown quantity at this point
Sounds like you're also asking where the SELECT statement would go... ?
Click on SQL view in your query (same button that lets you switch between Design and Datasheet view) and replace it with the one you got here. HTH
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting Hyperlink to Word infinitx General 0 05-16-2004 09:41 AM
Coding Item Classification in Combo Boxes infinitx General 0 03-22-2004 12:50 PM
Query not calculating totals Access Virgin Queries 4 04-30-2003 09:56 AM
Calculating Grouped Totals mpd Reports 2 03-25-2003 07:09 AM
Calculating totals in a form! Marilor Forms 10 06-26-2002 10:40 AM


All times are GMT -8. The time now is 09:58 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World