这是这个问题的续集。
我想在MySql select中将三列合并为一列。前两列是布尔值,第三列是字符串,有时为null。这导致了奇怪的结果:
Select *, (payment1_paid && ((payment2_paid || payment2_type ="none"))) as paid_in_full from payments
注意:payment1_paid
为布尔值,payment2_paid
为布尔值;payment2_type
为varchar。
注意:请忽略这个表的结构有多荒谬。在每一段糟糕的代码背后都有一个很长的解释:)
编辑:我对varchar值的Null不感兴趣。我只想知道它是否真的"没有"
提前感谢您的帮助!
如果null不感兴趣,那么对您来说:
Select *,
(payment1_paid && ((payment2_paid || (payment_type IS NOT NULL && payment_type="none")))
as paid_in_full
from payments
祝你好运!
我想您希望NULL为false?尝试(payment_paid IS NULL || payment2_type = "none")
Select *,
(payment1_paid && ((payment2_paid || coalesce(payment2_type,"null") ="none")))
as paid_in_full
from payments