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 |
|
invisible777
Starting Member
10 Posts |
Posted - 2007-12-04 : 12:41:58
|
I'm using a query to see how many times an action was recorded on a person. The query works, it returns this:John Smith 1John Smith 1John Smith 1Jane Doh 1Jane Doh 1Al Johnson 1but I need it to return totals like thisJohn Smith 3Jane Doh 2Al Johnson 1This is the query I am using:Select Player.First_Name, Player.Last_Name, COUNT(Action.Employee_ID)from Player INNER JOINPlayerVisit on PlayerVisit.Player_ID = Player.Player_IDjoin Treatment on Treatment.Visit_ID = PlayerVisit.Visit_IDjoin Action on Treatment.Action_ID = Action.Action_IDgroup by Player.First_Name, Player.Last_Name, Action.Employee_Id; |
|
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2007-12-04 : 12:44:48
|
| So are the numbers in a different column, try to not put Performs.Employee_Id; in the group by its not needed |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-12-04 : 12:45:39
|
| Select Patient.First_Name, Patient.Last_Name, COUNT(Performs.Employee_ID)...group by Patient.First_Name, Patient.Last_NameTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
invisible777
Starting Member
10 Posts |
Posted - 2007-12-04 : 12:52:11
|
| perfect, worked like a charm, thanks! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-12-05 : 02:22:34
|
quote: Originally posted by invisible777 I'm using a query to see how many times an action was recorded on a person. The query works, it returns this:John Smith 1John Smith 1John Smith 1Jane Doh 1Jane Doh 1Al Johnson 1but I need it to return totals like thisJohn Smith 3Jane Doh 2Al Johnson 1This is the query I am using:Select Player.First_Name, Player.Last_Name, COUNT(Action.Employee_ID)from Player INNER JOINPlayerVisit on PlayerVisit.Player_ID = Player.Player_IDjoin Treatment on Treatment.Visit_ID = PlayerVisit.Visit_IDjoin Action on Treatment.Action_ID = Action.Action_IDgroup by Player.First_Name, Player.Last_Name, Action.Employee_Id;
Grouping by the column that is part of aggregate function doesnt make any sense. It is just like not gouping by itMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|