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 |
matkwan
Starting Member
36 Posts |
Posted - 2007-05-08 : 09:52:31
|
Hi,Here is my 'Message' table:UserID, Message, Read1,'AAA',11,'BBB',11,'CCC',11,'DDD',01,'EEE',0I would like to return the count of total messages belonging to UserID = 1 and also the count of total Unread messages belonging to UserID = 1. For example, total 5 messages and 2 unread messages.Is it possible to achieve this in 1 SQL?Matt |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-08 : 10:01:22
|
[code]Select UserID, count(Message) as TotalCount, Sum(case when Read = 1 then 1 else 0 end) as ReadCount, Sum(case when Read = 0 then 1 else 0 end) as UnreadCountFrom TableGroup by UserID[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|
|