五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

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

發(fā)布日期:2022-02-21 13:19 | 文章來源:源碼中國

注意?。。?/p>

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

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

另外:

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

–如果null參與比較運算,則結果可視為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ù)里算是個奇葩,在比較中也比較特殊,下面記錄總結一下在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)

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

國外服務器租用

版權聲明:本站文章來源標注為YINGSOO的內(nèi)容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務

7x24全年不間斷在線

專屬顧問服務

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務熱線

關注
微信

關注官方微信
頂部