mysql IF-IFNULL和IF-ISNULL同样逻辑的运行差别

首先,目标记录是存在的

SELECT * FROM d_device_user_bind dub WHERE dub.`uid`='222222222221'

其次,

 SELECT dub.uid,dub.`device_id`,IF(IFNULL(dub.`device_id`,2)=2, 2, 1) isActivate FROM d_device_user_bind dub WHERE dub.del_flag=0 ORDER BY dub.`create_time` DESC LIMIT 8;

换一个语句:  SELECT dub.uid,dub.`device_id`,IF(dub.`device_id` IS NULL OR dub.`device_id`='', 2, 1) isActivate FROM d_device_user_bind dub WHERE dub.del_flag=0 ORDER BY dub.`create_time` DESC LIMIT 8;

再一个写法: SELECT dub.uid,dub.`device_id`,IF(ISNULL(dub.`device_id`), 2, 1) isActivate FROM d_device_user_bind dub WHERE dub.del_flag=0 ORDER BY dub.`create_time` DESC LIMIT 8;

不知道为什么会这样,也许是mysql的一个bug吧。

 

posted @ 2018-08-02 16:04  醉逍遥_001  阅读(647)  评论(0编辑  收藏  举报