色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

解決mysql使用not in 包含null值的問題

瀏覽:8日期:2023-10-07 10:25:57

注意!!!

select * from user where uid not in (a,b,c,null);

這個sql不回返回任何結果。要避免not in的list中出現null的情況。

另外:

?如果null參與算術運算,則該算術表達式的值為null。(例如:+,-,*,/ 加減乘除)

?如果null參與比較運算,則結果可視為false。(例如:>=,<=,<> 大于,小于,不等于)

?如果null參與聚集運算,則聚集函數都置為null(使用isnull(字段,0)等方式可以避免這種情況)。除count(*), count(1), count(0)等之外(count(字段) 字段為null的行不參與計數)。

--如果在not in子查詢中有null值的時候,則不會返回數據。

補充:MySQL in,not in,exists,not exists與null的恩恩怨怨

null這個東西在數據里算是個奇葩,在比較中也比較特殊,下面記錄總結一下在in,not in,exists,not exists中null對判斷結果的影響。

做一些描述聲明,在比較符左邊的我們稱為左比較符,在比較符右邊的我們稱為右比較符,例如1 in (1,2),那么in左邊的1是左比較符,in右邊的(1,2)是右比較符。

1.in

1.1當左比較符是null,任何情況下都返回null。

mysql> select null in (1,2);+---------------+| null in (1,2) |+---------------+| NULL |+---------------+1 row in set (0.00 sec)mysql> select null in (1,2,null);+--------------------+| null in (1,2,null) |+--------------------+| NULL |+--------------------+1 row in set (0.00 sec)

1.2當右比較符包含null,只當左比較符不為null,且右比較符包含左比較符時,返回1,其他情況均返回null。

mysql> select null in (1,2,null);+--------------------+| null in (1,2,null) |+--------------------+| NULL |+--------------------+1 row in set (0.00 sec)mysql> select 3 in (1,2,null);+-----------------+| 3 in (1,2,null) |+-----------------+| NULL |+-----------------+1 row in set (0.00 sec)mysql> select 1 in (1,2,null);+-----------------+| 1 in (1,2,null) |+-----------------+| 1 |+-----------------+1 row in set (0.00 sec)2.not in

2.1當左比較符為null,任何情況都返回null。

mysql> select null not in (1,2,null);+------------------------+| null not in (1,2,null) |+------------------------+| NULL |+------------------------+1 row in set (0.00 sec)mysql> select null not in (1,2);+-------------------+| null not in (1,2) |+-------------------+| NULL |+-------------------+1 row in set (0.00 sec)

2.2當右比較符包含null,當右比較符包含左比較符時返回0,其他情況均返回null。

mysql> select 1 not in (1,2,null);+---------------------+| 1 not in (1,2,null) |+---------------------+| 0 |+---------------------+1 row in set (0.00 sec)mysql> select 1 not in (2,3,null); +---------------------+| 1 not in (2,3,null) |+---------------------+| NULL |+---------------------+1 row in set (0.00 sec)3.exists

exists子查詢返回null時判斷為真。

mysql> select exists (select null);+----------------------+| exists (select null) |+----------------------+| 1 |+----------------------+1 row in set (0.00 sec)4.not exists

not exists子查詢返回null時判斷為假。

mysql> select not exists (select null);+--------------------------+| not exists (select null) |+--------------------------+| 0 |+--------------------------+1 row in set (0.00 sec)

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: MySQL 數據庫
相關文章:
主站蜘蛛池模板: 精品中文字幕一区在线 | 台湾三级香港三级在线理论 | 日韩看片 | 国产中文在线视频 | 久草在线最新视频 | 香蕉成人在线视频 | 亚洲成a人片在线观看中文 亚洲成a人片在线观看中文!!! | xx另类性欧美 | 中文字幕精品一区二区三区视频 | 精品久久久久久亚洲 | 久久亚洲一级α片 | 美女扒开腿让男人桶爽免费动态图 | 精品久久久久久久久久香蕉 | 日韩成人黄色片 | 大视频在线爱爱爱爱 | 在线精品免费视频 | 久久精品国产亚洲精品2020 | 国产精品国产三级国产专播 | 国产乱码一区二区三区四 | 成人久久久久 | 狠狠一区 | 免费播放欧美毛片 | 国产精品黄页网站在线播放免费 | 中文国产日韩欧美视频 | 国产欧美一区二区 | 亚洲欧美日韩国产精品影院 | 亚洲性久久久影院 | 亚洲男人的天堂久久无 | 久久.com| 一级特级aaa毛片 | 久久综合中文字幕一区二区 | freesex寂寞老妇hd | 久久精品亚洲综合一品 | 欧美成人做性视频在线播放 | 久久99精品视香蕉蕉 | 亚洲精品成人久久久影院 | 国产自愉自愉全免费高清 | 欧美另类孕交免费观看 | 精品一区二区三区四区在线 | 免费一级成人免费观看 | gdcm01果冻传媒 |