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 |
|
tim8w
Starting Member
10 Posts |
Posted - 2011-09-02 : 14:48:25
|
| I have a Table that contains two fields, Name and Status.Each record can contain identical entries for Name and Status, i.e.Name StatusPerson1 1Person1 2Person1 1Person1 3Person2 1Person2 3Person3 1After the query, I need the following output:Name Count (where Status = 1 or 3)Person1 3Person2 2Person3 1Is such a query possible?So far the best I have is:SELECT Name, Status, COUNT(*) AS CountFROM TableGROUP BY Name, StatusHAVING (Status IN (1,3))ORDER BY NameBut this query produces:Name Status Count (where Status = 1 or 3)Person1 1 2Person1 3 1Person2 1 1Person2 3 1Person3 1 1Any ideas? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|