SQL count specific value over multiple columns and rows

后端 未结 5 1224
甜味超标
甜味超标 2021-01-18 06:35

I feel as if this should be quite easy, but can\'t seem to find a solution. Suppose I have the following table:

|--------||---||---||---||---||---||---||---|         


        
5条回答
  •  感动是毒
    2021-01-18 07:28

    SELECT SUM(
        IF(q1 = 1, 1, 0) +
        IF(q2 = 1, 1, 0) +
        IF(q3 = 1, 1, 0) +
        IF(q4 = 1, 1, 0) +
        IF(q5 = 1, 1, 0) +
        IF(q6 = 1, 1, 0) +
        IF(q7 = 1, 1, 0)
    )
    FROM table
    WHERE Company = 'abc'
    

提交回复
热议问题