Sqlite - SELECT COUNT (* how many times the value is stored *)

I have a database of questions and answers. In the answers a specific question will save a yes / no entry to the database.

So, my table has an answer column that will have a yes or no value.

I want to be able to count how many times yes is stored and how many times no is stored.

Therefore, I could do this using two queries, for example:

SELECT COUNT(*) WHERE answer="yes";
SELECT COUNT(*) WHERE answer="no";

Is there a way to do this in a single request?

thank

+3
source share
3 answers

group it:

select answer, count(*) from yourtable group by answer;
+7
source

Try this one

SELECT
sum(CASE WHEN answer="yes" THEN 1 ELSE 0 END) countyes,
sum(CASE WHEN WHERE answer="no" THEN 1 ELSE 0 END) countNO
FROM table
+1
source
SELECT "yes answers", COUNT(*) WHERE answer="yes"
UNION 
SELECT "no answers", COUNT(*) WHERE answer="no";
0
source

All Articles