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.
Author |
Topic |
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2012-01-28 : 12:57:11
|
I have 2 tablesOrdersorderID UserID salesUserUserID FirstName LastnameI 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???DaveHelixpoint Web Developmenthttp://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 ShawSQL Server MVP |
 |
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2012-01-28 : 14:19:01
|
so sum()??DaveHelixpoint Web Developmenthttp://www.helixpoint.com |
 |
|
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 saleGroup by the UserID columnAre you familiar with the SELECT, JOIN and GROUP BY clauses?--Gail ShawSQL Server MVP |
 |
|
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 ShawSQL Server MVP |
 |
|
helixpoint
Constraint Violating Yak Guru
291 Posts |
Posted - 2012-01-28 : 14:40:56
|
Yup. Got it |
 |
|
|
|
|