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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL Joins ??

Author  Topic 

SQLNoob81
Starting Member

38 Posts

Posted - 2010-11-10 : 10:00:24
Hi Guys.

I have 3 select statements

select User, Sum(Fee) as TotalSales from Sales group by user
select User, Count(ID) as NoOfClients from Clients group by user
select User, Sum(SalesFee) as ValueOfQuotes from Quotes group by user

I would like all 3 of these combined into one select statement to give results like this:

User TotalSales NoOfClients ValueOfQuotes
User1 5000 100 2500
User2 4500 120 3500
User3 10000 150 7000


Hope this makes sense?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-10 : 10:34:00
[code]
select s.User,s.TotalSales,c.NoOfClients,q.ValueOfQuotes
from (select User, Sum(Fee) as TotalSales from Sales group by user)s
INNER JOIN (select User, Count(ID) as NoOfClients from Clients group by user) c
ON c.User = s.User
INNER JOIN (select User, Sum(SalesFee) as ValueOfQuotes from Quotes group by user)q
ON q.User = s.User
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SQLNoob81
Starting Member

38 Posts

Posted - 2010-11-11 : 01:51:25
Thanks visakh16

U ARE THE MAN!!!
Go to Top of Page
   

- Advertisement -