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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select with group by with criteria

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2011-10-06 : 06:33:14
I now have

select ddi,count(d),sum(duration),sum(rate) from #stats group by ddi

I want to add another count that counts how many fields for the same ddi have a null rate

How can I do this within the select statement?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-10-06 : 06:45:42
Try:
select
ddi,
count(d),
sum(duration),
sum(rate),
sum(case when rate IS NULL then 1 else 0 end) as NULLrate
from #stats
group by ddi



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2011-10-06 : 07:07:03
thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-10-06 : 07:45:05
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -