以SQL Server
为例
col1, col2, col3, col4
id1, 0.00, 0.00, 0.00
id2, 0.00, 1.00, 0.00
id3, 5.55, 2.22, 0.00
id4, 0.00, 0.00, 0.00
id5, 1.11, 2.22, -3.33
我想实现一个WHERE
子句,这样当col2,col3和col4中的所有值都等于零时,该行将从结果中排除。
我尝试过以下WHERE
条款
where col2!=0 and col3!=0 and col4!=0
这只返回id5行,当我所追求的是返回id2,id3和id5时。
我知道where子句是错误的,但不确定要尝试的其他东西。
我已经考虑过在列之间进行求和,但这是不可取的,因为小数可以在任一方向上进行,也可能在关闭机会等于零时,即使所有值都已填充
你的意图是:
where not (col2=0 and col3=0 and col4=0)
解释为没有全部三个零的所有行。
要么
where col2!=0 or col3!=0 or col4!=0
它解释为至少有一列非零的所有行。