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
 How to Get the status count

Author  Topic 

shagil.a.gopinath
Starting Member

14 Posts

Posted - 2015-03-07 : 06:51:57
Hi,

I have a table of status_Master where the details are maintained by street name with status but I need the result of total count by each status against the street name.

Status_Master

Sl No StreetName Status
1        Delhi        Pending
2        Delhi        Working
3        Delhi        Working
4        Mumbai        Pending
5        Mumbai        Pending
6        Delhi        Working
7        Delhi        Problem
8        Mumbai        Working
9        Mumbai        Problem
50        .        .
100        .        .
200        .        .


Result as below

StreetName Working Pending Problem

Delhi               3            1            1
Mumbai            1            2            1

Can anyone please help me



Thanks & Regards



James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2015-03-07 : 08:24:48
[code]select
StreetName,
SUM(case when [Status] = 'Working' then 1 else 0 end) as Working,
SUM(case when [Status] = 'Pending' then 1 else 0 end) as Pending,
SUM(case when [Status] = 'Problem' then 1 else 0 end) as Problem
from
Status_Master
group by
StreetName;[/code]
Go to Top of Page

shagil.a.gopinath
Starting Member

14 Posts

Posted - 2015-03-07 : 11:20:04

Thanks you so much, its worked perfectly for the scenario

Thanks & Regards



Go to Top of Page
   

- Advertisement -