关于Mysql中的case when 判断Null的坑

无论 case XX when null then 0 else 1;

还是 case xx when xx is null then 0 else 1;

都无法正确判断。因为case 后面commission_pct 的值有两种:真实值或者为null,而 when 后面的commission_pct is null 也有两个值:true或者false,所以case 后面为null时候永远无法跟true或false匹配,因此输出不为null。

正确写法是

case XXXX is null when true then 0 else 1

posted @ 2020-08-20 18:02  DialoguezZ  阅读(993)  评论(0)    收藏  举报