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 |
|
gretty
Starting Member
6 Posts |
Posted - 2009-10-25 : 00:31:36
|
Hellomy objective is to do the below but I get an error because of my group by statement?? quote: Display each rep number and name and their total number of customers
The tables involved are:Customer: quote: CUSTOMER_NUM PRIMARY KEY,CUSTOMER_NAME REP_NUM CHAR
Rep quote: REP_NUM PRIMARY KEY,LAST_NAME FIRST_NAMESTREET CITY STATEZIPCOMMISSION
select last_name,first_name, rep.rep_num, count(*)from customer C,rep Rwhere C.rep_num = R.rep_numgroup by R.rep_num; |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-10-25 : 08:24:59
|
| WHat you had is a ommon mistake made by beginners, you can't just choose two tables to use in the FROM Statement, you must 'Join' them on a UniqueIDentifier or something common to both tables. WHat I have done should give you some Idea of how to use it.select r.rep_num, r.First_Name, r.Last_Name, c. count(*)from customer CInner Join Rep r on r.Rep_num = c.Rep_numwhere C.rep_num = R.rep_numgroup by R.rep_num, r.First_Name, r.Last_NameOrder By r.Rep_numHope this helps.[/fail at query] |
 |
|
|
|
|
|