我需要将三列中的值相加。值大于1时,需要填充特定的词组。
所以...示例
From temp_table_tx = count_of_x
From temp_table_ty = count_of_y
From temp_table_tz = count_of_z
我目前有以下问题,这只会给我一个错误。
CASE
WHEN (tx.count_of_x + ty.count_of_y + tz.count_of_z) >1 THEN 'Exception_present'
WHEN (tx.count_of_x + ty.count_of_y + tz.count_of_z) <1 THEN 'No_Exceptions'
ELSE 'error'
End As exceptions
答案 0 :(得分:0)
如果任何计数为'error'
,您将得到NULL
。因此,这可能会解决您的问题:
(CASE WHEN coalesce(tx.count_of_x, 0) + coalesce(ty.count_of_y, 0) + coalesce(tz.count_of_z, 0) > 1
THEN 'Exception_present'
WHEN coalesce(tx.count_of_x, 0) + coalesce(ty.count_of_y, 0) + coalesce(tz.count_of_z, 0) < 1 THEN 'No_Exceptions'
ELSE 'error'
END) As exceptions
但是,将计数精确为“ 1”视为错误是很奇怪的。