SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query for a basic report
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Priya2013
Starting Member

Australia
2 Posts

Posted - 02/26/2013 :  17:51:51  Show Profile  Reply with Quote
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

Edited by - Priya2013 on 02/26/2013 18:22:22

jimf
Flowing Fount of Yak Knowledge

USA
2870 Posts

Posted - 02/26/2013 :  18:16:52  Show Profile  Reply with Quote
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

Australia
2 Posts

Posted - 02/26/2013 :  18:22:54  Show Profile  Reply with Quote
Thanks Jim,

Sorry for the confusion, I just corrected the data.

Priya

PS: That helped me. thanks.

Edited by - Priya2013 on 02/26/2013 18:30:59
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000