eric eric - 5 months ago 11
SQL Question

How can I SUM rows that have at least X Boolean 1s? SOLVED

Example table:

col1 col2 col3 col4
Abe 1 0 1
Bob 0 1 0
Cam 1 1 1
Dan 1 0 0
Eve 1 1 1


How can I query so that I can
SUM
how many people in
col1
have a total of 2 1s? (So, since Abe is the only person with 2 1s, the query outputs the number 1.)

Thanks.

Answer
Select count(*) from table_name where col2+col3+col4=2