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 |
Priya2013
Starting Member
2 Posts |
Posted - 2013-02-26 : 17:51:51
|
Hi All,Can anyone suggest me a query for the following basic report?The table/data is like this..Party_id Party_Site_id Status-----------------------------------111 101 Active111 102 Active111 103 Inactive222 201 Inactive222 202 Active222 203 InactiveThe output I want is like this..Party_id Active_Count Inactive_Count---------------------------------------111 2 1222 1 2Please can anyone help me.Thanks in Advance/PriyaPriya |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2013-02-26 : 18:16:52
|
I don't see the logic in how to get your results form your sample data, but this should be a good startSELECT Party_ID ,SUM(CASE WHEN Status = 'ACTIVE' THEN 1 ELSE 0 END) as Active_Count ,SUM(CASE WHEN Status = 'INACTIVE' THEN 1 ELSE 0 END) as Active_CountFROM yourTableGROUP BY Party_IDJimEveryday I learn something that somebody else already knew |
|
|
Priya2013
Starting Member
2 Posts |
Posted - 2013-02-26 : 18:22:54
|
Thanks Jim,Sorry for the confusion, I just corrected the data.PriyaPS: That helped me. thanks. |
|
|
|
|
|