show columns in m like 'fl-6ren">
gpt4 book ai didi

mysql - 为什么 "where not in"查询结果为 0

转载 作者:行者123 更新时间:2023-11-29 02:56:29 25 4
gpt4 key购买 nike

<分区>

mysql> show columns in m like 'fld';
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| fld | varchar(45) | YES | MUL | NULL | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> show columns in i like 'fld';
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| fld | varchar(45) | YES | MUL | NULL | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.02 sec)

mysql> select count(distinct fld) from i;
+---------------------+
| count(distinct fld) |
+---------------------+
| 27988 |
+---------------------+
1 row in set (0.03 sec)

mysql> select count(distinct fld) from m;
+---------------------+
| count(distinct fld) |
+---------------------+
| 72558 |
+---------------------+
1 row in set (0.07 sec)

根据我对相关表格的了解,上述结果似乎是合理的。

mysql> select count(*) from m where fld not in (select fld from i);
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.11 sec)

最后那个结果好像不太合理。 There must be m 中的 一些fld 不在 i 中!有人可以解释为什么我得到 0 作为结果吗?


为了完整性(因为我怀疑它可能是相关的),我还会粘贴这个结果:

mysql> select count(*) from m where fld is null;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)

编辑:为了回复评论,我也在编辑以下信息,以防有人回答我的问题:

  • select count(*) from m join i using (fld) 产生 9350;用 左连接, 73087;用右连接, 28872.
  • 从 fld 为 null 的 i 中选择 count(*) 产生 810。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com