与使用in时不同:
在使用in 时:
SELECT COUNT(name) FROM CVE WHERE name NOT IN (‘CVE-1999-0001‘, ‘CVE-1999-0002‘);
SELECT COUNT(name) FROM CVE WHERE name NOT IN (‘CVE-1999-0001‘, ‘CVE-1999-0002‘,NULL);
二者结果相同;
在使用not in时:
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)
时间: 2024-11-07 07:49:11