“<=>”是什么意思? MySQL 中的意思是什么?

发布于 2024-10-09 13:42:20 字数 48 浏览 8 评论 0 原文

MySQL 中 <=> 的含义和作用是什么?

What does <=> in MySQL mean and do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦与时光遇 2024-10-16 13:42:20

手册说明了一切:

NULL 安全等于。这个运营商
执行相等比较,例如
= 运算符,但返回 1
如果两个操作数都为 NULL,则大于 NULL,
如果有一个操作数则为 0 而不是 NULL
为 NULL。

mysql> select NULL <=> NULL;
+---------------+
| NULL <=> NULL |
+---------------+
|             1 |
+---------------+
1 row in set (0.00 sec)

mysql> select NULL = NULL;
+-------------+
| NULL = NULL |
+-------------+
|        NULL |
+-------------+
1 row in set (0.00 sec)

mysql> select NULL <=> 1;
+------------+
| NULL <=> 1 |
+------------+
|          0 |
+------------+
1 row in set (0.00 sec)

mysql> select NULL = 1;
+----------+
| NULL = 1 |
+----------+
|     NULL |
+----------+
1 row in set (0.00 sec)

mysql> 

The manual says it all:

NULL-safe equal. This operator
performs an equality comparison like
the = operator, but returns 1 rather
than NULL if both operands are NULL,
and 0 rather than NULL if one operand
is NULL.

mysql> select NULL <=> NULL;
+---------------+
| NULL <=> NULL |
+---------------+
|             1 |
+---------------+
1 row in set (0.00 sec)

mysql> select NULL = NULL;
+-------------+
| NULL = NULL |
+-------------+
|        NULL |
+-------------+
1 row in set (0.00 sec)

mysql> select NULL <=> 1;
+------------+
| NULL <=> 1 |
+------------+
|          0 |
+------------+
1 row in set (0.00 sec)

mysql> select NULL = 1;
+----------+
| NULL = 1 |
+----------+
|     NULL |
+----------+
1 row in set (0.00 sec)

mysql> 
原来分手还会想你 2024-10-16 13:42:20

这是NULL安全等于运算符

<=> 之间的区别和 = 是当一个或两个操作数都是 NULL 值时。例如:

NULL <=> NULL gives True
NULL = NULL   gives NULL

以下是值 1、2 和 NULL 的 <=> 比较的完整表格:

     |  1      2    NULL
-----+-------------------
1    | True   False False
2    | False  True  False
NULL | False  False True

与普通相等运算符比较:

     |  1      2    NULL
-----+-------------------
1    | True   False NULL
2    | False  True  NULL
NULL | NULL   NULL  NULL

It's the NULL-safe equal operator.

The difference between <=> and = is when one or both of the operands are NULL values. For example:

NULL <=> NULL gives True
NULL = NULL   gives NULL

Here is the full table for the <=> comparison of values 1, 2 and NULL:

     |  1      2    NULL
-----+-------------------
1    | True   False False
2    | False  True  False
NULL | False  False True

Compare to the ordinary equality operator:

     |  1      2    NULL
-----+-------------------
1    | True   False NULL
2    | False  True  NULL
NULL | NULL   NULL  NULL
要走就滚别墨迹 2024-10-16 13:42:20

<=> 是所谓的 NULL-安全相等运算符

SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL; 
-> 1, 1, 0

SELECT 1 = 1, NULL = NULL, 1 = NULL;
-> 1, NULL, NULL

<=> is a so called NULL-safe-equality operator.

SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL; 
-> 1, 1, 0

SELECT 1 = 1, NULL = NULL, 1 = NULL;
-> 1, NULL, NULL
画▽骨i 2024-10-16 13:42:20

与SQL标准关键字DISTINCT相同

SELECT * FROM somewhere WHERE `address1` is not distinct from `address2`

It's the same as SQL standard keyword DISTINCT

SELECT * FROM somewhere WHERE `address1` is not distinct from `address2`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文