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 2008 Forums
 Transact-SQL (2008)
 How to do this

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2012-01-28 : 12:57:11
I have 2 tables
Orders

orderID UserID sales


User

UserID FirstName Lastname

I want to create a a sql statement that list all users and there total sales. I do not want the users that have not made a sale???

Dave
Helixpoint Web Development
http://www.helixpoint.com

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-28 : 13:21:59
Inner join the two tables, aggregate the sale by UserID.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2012-01-28 : 14:19:01
so sum()??

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-28 : 14:26:29
quote:
Originally posted by helixpoint

English please



Table definitions and sample data please.

Where's the problem?
Join the two tables with an inner join.
Aggregate the sale
Group by the UserID column

Are you familiar with the SELECT, JOIN and GROUP BY clauses?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-28 : 14:29:43
Sum would indeed be the function you need for the aggregation. Is the rest OK?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2012-01-28 : 14:40:56
Yup. Got it
Go to Top of Page
   

- Advertisement -