Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 simple query to JOIN three tables

Author  Topic 

mameha1977
Starting Member

3 Posts

Posted - 2012-10-19 : 06:11:45
I wish to find out the total sales per industry using SQL.

Tables:
- Sales
- Customer
- Industry

The tables are linked as follows:
- Sales is linked to Customer by Customer_ID
- Customer is linked to Industry by Industry_ID

The Sales table contains each sale (price + customer_id)
The Customer table contains each customer (customer_id, industry_id)
The Industry table contains each industry (industry_id, industry_name)

I simply want to get the total sales for each Industry using SQL, with the result looking like this:

INDUSTRY_NAME | TOTAL SALES
Industry4 9876
Industry2 8889
Industry3 7787
Industry1 2898

Can anyone work out the Query needed to select this data?

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-19 : 06:28:04

SELECT industry_name, SUM( s.price) TotalSales
FROM Industy i
JOIN Customer c ON i.indusrty_id = c.industry_id
JOIN Sales s ON s.customer_id = c.dustomer_id
GROUP BY industry_name


--
Chandu
Go to Top of Page

mameha1977
Starting Member

3 Posts

Posted - 2012-10-19 : 06:37:36
Thanks bandi.

I tried this:

SELECT I.Industry, SUM(S.PRICE) AS TotalSales
FROM TEG_Industry I
JOIN TEG_Customer C ON I.IndustryID = C.Branch
JOIN TEG_sales S ON S.CompanyID = C.[Customer No]
GROUP BY Industry;

But it gives an error: "syntax error in FROM clause"

Any idea what is wrong?
Go to Top of Page

mameha1977
Starting Member

3 Posts

Posted - 2012-10-19 : 06:40:59
FYI: I am using MS Access
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-10-19 : 07:14:53
quote:
Originally posted by mameha1977

FYI: I am using MS Access



This is SQL Server forum. You can find solution in MS Access related Forums...

--
Chandu
Go to Top of Page
   

- Advertisement -