这是this question的续集。
我想在MySql选择中将三列合并为一列。前两列是布尔值,第三列是字符串,有时是null。这会导致奇怪的结果:
Select *, (payment1_paid && ((payment2_paid || payment2_type ="none"))) as paid_in_full from payments
注意: payment1_paid
是布尔值,payment2_paid
是布尔值,payment2_type
是varchar。
注意:请忽略此表的结构有多荒谬。在每一段糟糕的代码背后都有一个很长的解释:)
编辑:对于varchar值,Null对我来说并不感兴趣。我只想知道它是否真的“无”。
提前感谢您的帮助!
答案 0 :(得分:5)
如果null不感兴趣那么你呢:
Select *,
(payment1_paid && ((payment2_paid || (payment_type IS NOT NULL && payment_type="none")))
as paid_in_full
from payments
祝你好运!
答案 1 :(得分:1)
我猜你想要NULL为假?试试(payment_paid IS NULL || payment2_type = "none")
答案 2 :(得分:1)
Select *,
(payment1_paid && ((payment2_paid || coalesce(payment2_type,"null") ="none")))
as paid_in_full
from payments