我有一个ID
,Numerator
和Denominator
列的表。
当分子和分母在同一行时,我该如何去除零呢?
我想我可以做一个case when语句,例如,case当分子= '0'和分母= '0'然后删除,但我的语法是关闭的。
输入表示例
ID Numerator Denominator
------------------------
1 1 0
2 0 0
输出表示例:
ID Numerator Denominator
------------------------
1 1 0
2 <--- In SQL Server, it would possibly show up as NULL since it is blank data.
您将使用两个大小写表达式:
select t.*,
(case when numerator <> 0 or denominator <> 0 then numerator end) as new_numerator,
(case when numerator <> 0 or denominator <> 0 then denominator end) as new_denominator
from t;