av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

注意!!!

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

這個sql不回返回任何結(jié)果。要避免not in的list中出現(xiàn)null的情況。

另外:

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

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

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

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

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

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

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

1.in

1.1當(dāng)左比較符是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當(dāng)右比較符包含null,只當(dāng)左比較符不為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當(dāng)左比較符為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當(dāng)右比較符包含null,當(dāng)右比較符包含左比較符時返回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)

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

標(biāo)簽: MySQL 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 久久精品黄色 | 欧美日韩少妇 | 激情视频一区 | 色一情一乱一乱一区91av | 青久久 | 成人一区在线观看 | 成人在线免费看 | 三级视频网| 成人在线免费av | 国产精品99久久久久久www | 欧美日韩高清在线 | 午夜久久久| 国产欧美日韩综合精品 | www.粉色视频在线观看 | 黄色三级av | 99国产在线观看 | 日本天堂在线 | 国产91在线播放 | 能看的毛片 | 色播久久| 日韩免费 | 成人爱爱 | 日韩久久av | 日本a级大片 | 国产日产精品一区二区三区的介绍 | 国产探花视频在线观看 | 福利视频网站 | 日韩小视频 | 日韩久久久久久久 | 国产伦精品一区二区三区视频网站 | 国产福利在线视频 | 国产精品一区二区在线免费观看 | 国产女人水真多18毛片18精品 | 国产一区二区三区免费 | 免费av片 | 一级理论片 | 色婷婷亚洲 | 中文字幕2021| 天天干天天操天天爽 | 欧美一级在线观看 | 色站综合|