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 |
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2010-01-15 : 07:10:59
|
Hi,Following is my requirementuserid ssid Fname Status1 101 1@ 02 101 2@ 13 101 3@ 14 101 4@ 25 102 5@ 0I want result like belowssid, status_0_cnt, status_x_cnt101 1 3 102 1 0I want results groupby ssid. But one count for Zero and another count for remaining status values. developer :) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-15 : 07:17:23
|
| select ssid,sum(case when status=0 then 1 else 0 end) as status_0_cnt,sum(case when status>0 then 1 else 0 end) as status_x_cntfrom your_tablegroup by ssidMadhivananFailing to plan is Planning to fail |
 |
|
|
satish.gorijala
Posting Yak Master
182 Posts |
Posted - 2010-01-15 : 07:22:54
|
Thanks Madhavan. If i want to add Fname to output..how can i write query?quote: Originally posted by madhivanan select ssid,sum(case when status=0 then 1 else 0 end) as status_0_cnt,sum(case when status>0 then 1 else 0 end) as status_x_cntfrom your_tablegroup by ssidMadhivananFailing to plan is Planning to fail
developer :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-15 : 07:29:33
|
quote: Originally posted by satish.gorijala Thanks Madhavan. If i want to add Fname to output..how can i write query?quote: Originally posted by madhivanan select ssid,sum(case when status=0 then 1 else 0 end) as status_0_cnt,sum(case when status>0 then 1 else 0 end) as status_x_cntfrom your_tablegroup by ssidMadhivananFailing to plan is Planning to fail
developer :)
Post expected resultMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-15 : 12:40:08
|
sounds like thisselect ssid,Fname,sum(case when status=0 then 1 else 0 end) over (partition by ssid) as status_0_cnt,sum(case when status>0 then 1 else 0 end) over (partition by ssid) as status_x_cntfrom your_table |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-01-15 : 12:59:40
|
Hmmm ... I read it that Fname, being variable per ssid, and unique within the sample data, would need to be presented as comma delimited list for each ssid, or somesuch.Are we taking bets? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-18 : 01:55:52
|
quote: Originally posted by Kristen Hmmm ... I read it that Fname, being variable per ssid, and unique within the sample data, would need to be presented as comma delimited list for each ssid, or somesuch.Are we taking bets? 
Wait until OP posts back MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|