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
 Self Joins

Author  Topic 

cool.mugil
Starting Member

32 Posts

Posted - 2009-03-20 : 06:20:46
Hi,
In my table i have following fields

ID,Date,Status

I want to get the count based on the status.Which is p for present,a for absent.

The scenario for status is either values will be present or absent or it will have any one.

Please guide me how to write query for this.

Thanks in advance.

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-20 : 06:49:31
[code]select
[ID],[Date],
CountPresent=sum(case when status='p' then 1 else 0 end),
CountAbsent= sum(case when status='a' then 1 else 0 end),
from
yourtable
group by
[ID],[Date][/code]
Go to Top of Page

cool.mugil
Starting Member

32 Posts

Posted - 2009-03-20 : 07:44:47
Thanks for help.It works fine.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-20 : 07:46:56
np
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-20 : 09:24:42
does date field contain timepart also?
Go to Top of Page
   

- Advertisement -