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 2000 Forums
 SQL Server Development (2000)
 Query Question...

Author  Topic 

benko
Starting Member

24 Posts

Posted - 2004-11-25 : 11:26:24
Ok im doing a simple query from one table. The columns im getting are the date but i also need a column for a count for YES and a column count for NO. My where clause in where status is YES or where status is NO. How do i get the count for those 2 columns. Thanks in advance.

Select theDate, someCount?, someCount?
from tblstatus
where status='YES' OR status='NO'

I DUNNO?!!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-11-25 : 11:48:57
Will this do:

select theDate,
sum(case when status='YES' then 1 else 0 end) as YesCount,
sum(case when status='NO' then 1 else 0 end) as NoCount
from tblstatus
where status='YES' OR status='NO'
group by theDate

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -