您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL中NOT IN语句对NULL值的处理

2026/1/9 4:14:35发布17次查看
顺便提一下mysql中正则表达式匹配的简单使用:select count(alarmid)from alarmwhere (cve not rlike
mysql> select count(name) from cve where name not in ('cve-1999-0001', 'cve-1999-0002');
+-------------+
| count(name) |
+-------------+
|       17629 |
+-------------+
1 row in set (0.02 sec)
mysql> select count(name) from cve where name not in ('cve-1999-0001', 'cve-1999-0002', null);
+-------------+
| count(name) |
+-------------+
|           0 |
+-------------+
1 row in set (0.01 sec)
当在子查询中出现null的时候,结果就一定是0了。查了一下手册,确实有这样的说法。所以最后实际采用了这样的查询:
select count(distinct name)
from cve
where name not in (select cveid from cve_sig where cveid is not null)
顺便提一下mysql中正则表达式匹配的简单使用:
select count(alarmid)
from alarm
where (cve not rlike '^cve-[0-9]{4}-[0-9]{4}$' or cve is null)
当然,rlike也可以写作regexp,我个人倾向于使用rlike,因为拼写接近like,可以见名知义。

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product