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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query for a basic report

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 Active
111 102 Active
111 103 Inactive
222 201 Inactive
222 202 Active
222 203 Inactive

The output I want is like this..
Party_id Active_Count Inactive_Count
---------------------------------------
111 2 1
222 1 2

Please can anyone help me.

Thanks in Advance/Priya

Priya

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 start

SELECT
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_Count
FROM yourTable
GROUP BY Party_ID

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Priya2013
Starting Member

2 Posts

Posted - 2013-02-26 : 18:22:54
Thanks Jim,

Sorry for the confusion, I just corrected the data.

Priya

PS: That helped me. thanks.
Go to Top of Page
   

- Advertisement -