mysql - Counts where more than one column is true -
i have table 7 true/false columns, how can select rows have 2 or more of columns set true?
here have far:
select count(*), c1,c2,c3,c4,c5,c6,c7 members 1 in (c1,c2,c3,c4,c5,c6,c7);
a true/false column 1 digit integer. unless have values other 0 , 1 stored or column nullable, can add columns , check whether result >= 2
select * members c1 + c2 + c3 + c4 + c5 + c6 + c7 >= 2
if there non-0 , non-1 entries, should correct beforehand. if can null, you'll need use where ifnull(c1, 0)...
Comments
Post a Comment