Count

1. Member
Join Date
Dec 1969
Posts
45

## Count

Hello,<BR><BR>I have two columns named &#039;applied&#039; and &#039;enrolled&#039;, which has only &#039;Y&#039; and &#039;N&#039; value. How can I count only the number of &#039;Y&#039; for both of the columns?<BR><BR>Thanks,<BR>Jenny

2. Senior Member
Join Date
Dec 1969
Posts
11,247

## Ahh hmm Not sure! maybe

Select Appliedcount, enrolledcount From<BR>((Select count(applied) as appliedcount From &#060;table&#062; where applied = &#039;y&#039;) as T1,<BR>(Select count(enrolled) as enrolledcount From &#060;table&#062; where enrolled = &#039;y&#039;) as T2)

3. Senior Member
Join Date
Dec 1969
Posts
2,892

## RE: Ahh hmm Not sure! maybe

If this is Access, couldn&#039;t you also do:<BR><BR>SELECT SUM(IIF(enrolled = &#039;y&#039;, 1, 0)) AS CountEnrolled,<BR>SUM(IIF(applied = &#039;y&#039;, 1, 0)) AS CountApplied<BR>FROM...<BR><BR>I know I am using SUM here, but if each y = 1 value to be summed, won&#039;t that return the count of y, in essence?<BR><BR>Just thinking out loud...<BR><BR>Kurt

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Yes, more efficienct...but for SQL Server..

...have to use CASE WHEN<BR><BR>SELECT SUM( CASE WHEN enrolled=&#039;y&#039; THEN 1 ELSE 0 END ) AS CountEnrolled,<BR> SUM( CASE WHEN applied=&#039;y&#039; THEN 1 ELSE 0 END ) AS CountApplied<BR>FROM table WHERE ...<BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•