SQL count specific value over multiple columns and rows

后端 未结 5 1170
甜味超标
甜味超标 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:26

    This is very weird assignment but:

    http://sqlfiddle.com/#!9/2e7aa/3

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

提交回复
热议问题