我怎么做布尔逻辑在MySql的两列,其中一个是一个Varchar吗?How do I do boolean logic on two columns in MySql, one of which is a Varchar?

- 此内容更新于:2014-12-30
主题:

原文:

This is the sequel to this question.

I would like to combine three columns into one on a MySql select. The first two columns are boolean and the third is a string, which is sometimes null. This causes strange results:

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

Note: payment1_paid is boolean, payment2_paid is boolean, payment2_type is varchar.

Note: Please ignore how ridiculous the structure of this table is. Behind every piece of bad code there is a long explanation :)

Edit: Null is not interesting to me for the varchar value. I only want to know if it's really "none."

Thanks in advance for your help!

解决方案:
如果空不是有趣的然后给你: 好运!
原文:

If null is not interesting then for you then:

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

Good luck!

解决方案:
我猜你想要空是假的吗?试(payment_paid空| | payment2_type =“没有”)
原文:

I guess you want NULL to be false? Try (payment_paid IS NULL || payment2_type = "none")

解决方案:
原文:
Select *, 
      (payment1_paid && ((payment2_paid || coalesce(payment2_type,"null") ="none"))) 
         as paid_in_full 
from payments