eric eric - 1 year ago 70
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
how many people in
have a total of 2 1s? (So, since Abe is the only person with 2 1s, the query outputs the number 1.)


Answer Source
Select count(*) from table_name where col2+col3+col4=2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download