Counting yes/no values

MrZimma

Registered User.
Local time
Today, 07:15
Joined
Nov 12, 2004
Messages
15
How can I set up a query to give me the total number of "yes" and "no" responses from a yes/no field?
 
Select count(MyCol) from MyTable where MyCol = true
Select count(MyCol) from MyTable where MyCol = false

unless you want it on one row

Select (Select count(MyCol) from MyTable where MyCol = true) as YesAnswers, (Select count(MyCol) from MyTable where MyCol = false) as NoAnswers

or you need to explain more?
 
I hate to ask, but yes, I need more explanation. You lost me after select. As in, I think I understand that it's a select query. But that's about it.
 
group by & count

Another way to do it in the query is select the field with yes/no and then another field in the table (ie item) and do a group by the yes/no field and count the item field.

here's a sample in SQL Vies - if you wanted to count how many companies have a website (Website is your y/n field) the code would be:

SELECT tbl_Company.website, Count(tbl_Company.Company) AS CountOfCompany
FROM tbl_Company
GROUP BY tbl_Company.website;

your result will be two rows:
Yes: 50
No: 15
 

Users who are viewing this thread

Back
Top Bottom