A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

"join" and "sum" over 3 tables



 
 
Thread Tools Display Modes
  #1  
Old March 13th, 2007, 05:44 AM posted to microsoft.public.access.queries
Joe Koenig
external usenet poster
 
Posts: 1
Default "join" and "sum" over 3 tables

Hi,

sorry if this question is a tad bit lame, but I ran out of practice re
SQL and and can't seem to solve this on my own.



Products
----------------------------------------------------
Product_ID_PK | Product_Name | Product_Price
----------------------------------------------------
1 | Shirt | $50
2 | Pants | $100
3 | Coat | $200
4 | Belt | $20
[...]



Salespersons
----------------------------------------------------
Salesperson_ID_PK | Salesperson_Name
----------------------------------------------------
1 | James Cooper
2 | Jim Brown
3 | Andrea Smith
[...]



Sales
----------------------------------------------------
Sales_ID_PK | Product_ID | Salesperson_ID | Amount
----------------------------------------------------
1 1 | 1 | 2 | 100
2 2 | 2 | 2 | 150
3 3 | 1 | 3 | 1000
4 4 | 2 | 3 | 1000
5 5 | 3 | 3 | 1100
6 6 | 4 | 3 | 500
[...]




So, I want to query the volume of sales per salesperson. The result
should look something like this:



Salesperson | Volume
-----------------------
James Cooper | $0
Jim Brown | $20000
Andrea Smith | $380000
[...]

i.e.: expr: Products.Product_Price*Sales.Amount


Thank you for your attention

Joe

P.S.: it might take me until Monday to give feedback
  #2  
Old March 15th, 2007, 10:14 AM posted to microsoft.public.access.queries
Michel Walsh
external usenet poster
 
Posts: 2,404
Default "join" and "sum" over 3 tables

SELECT SalesPersonName, SUM(ProductPrice)

FROM (Sales INNER JOIN Products
ON Sales.ProductID=Products.ProductID)
INNER JOIN SalesPerson
ON Sales.SalesPersonID=SalesPerson.SalesPersonID

GROUP BY SalesPersonName



Hoping it may help,
Vanderghast, Access MVP


"Joe Koenig" wrote in message
...
Hi,

sorry if this question is a tad bit lame, but I ran out of practice re
SQL and and can't seem to solve this on my own.



Products
----------------------------------------------------
Product_ID_PK | Product_Name | Product_Price
----------------------------------------------------
1 | Shirt | $50
2 | Pants | $100
3 | Coat | $200
4 | Belt | $20
[...]



Salespersons
----------------------------------------------------
Salesperson_ID_PK | Salesperson_Name
----------------------------------------------------
1 | James Cooper
2 | Jim Brown
3 | Andrea Smith
[...]



Sales
----------------------------------------------------
Sales_ID_PK | Product_ID | Salesperson_ID | Amount
----------------------------------------------------
1 1 | 1 | 2 | 100
2 2 | 2 | 2 | 150
3 3 | 1 | 3 | 1000
4 4 | 2 | 3 | 1000
5 5 | 3 | 3 | 1100
6 6 | 4 | 3 | 500
[...]




So, I want to query the volume of sales per salesperson. The result
should look something like this:



Salesperson | Volume
-----------------------
James Cooper | $0
Jim Brown | $20000
Andrea Smith | $380000
[...]

i.e.: expr: Products.Product_Price*Sales.Amount


Thank you for your attention

Joe

P.S.: it might take me until Monday to give feedback



 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.