2

这是这个问题的后续。

我想在 MySql 选择中将三列合并为一列。前两列是布尔值,第三列是字符串,有时为空。这会导致奇怪的结果:

Select *, (payment1_paid && ((payment2_paid || payment2_type ="none"))) as paid_in_full from payments 

注意: payment1_paid是布尔值,payment2_paid是布尔值,payment2_type是varchar。

注意:请忽略此表的结构多么荒谬。每一段糟糕的代码背后都有一个很长的解释:)

编辑:对于 varchar 值,我对 Null 不感兴趣。我只想知道它是否真的“无”。

在此先感谢您的帮助!

4

3 回答 3

5

如果 null 不感兴趣,那么对您来说:

Select *, 
      (payment1_paid && ((payment2_paid || (payment_type IS NOT NULL && payment_type="none"))) 
         as paid_in_full 
from payments

祝你好运!

于 2008-10-29T23:25:54.010 回答
1

我猜你希望 NULL 是假的?尝试 (payment_paid IS NULL || payment2_type = "none")

于 2008-10-29T23:12:49.247 回答
1
Select *, 
      (payment1_paid && ((payment2_paid || coalesce(payment2_type,"null") ="none"))) 
         as paid_in_full 
from payments
于 2008-10-29T23:13:06.737 回答