gpt4 book ai didi

mysql - 为什么是 MySQL ... 为什么?

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:30 24 4
gpt4 key购买 nike

那么,对于 mysql,为什么彼此不相等的事物会彼此相等?例如,为什么...

mysql> SELECT '3' = 3;
+---------+
| '3' = 3 |
+---------+
| 1 |
+---------+

只是,为什么?

更重要的是......

mysql> SELECT 0 = '';
+--------+
| 0 = '' |
+--------+
| 1 |
+--------+

但是,为什么?

还有……

mysql> SELECT '3x' into @foo;
Query OK, 1 row affected (0.00 sec)

mysql> SELECT @foo, CAST(@foo as signed), @foo = CAST(@foo as signed);
+------+----------------------+-----------------------------+
| @foo | CAST(@foo as signed) | @foo = CAST(@foo as signed) |
+------+----------------------+-----------------------------+
| 3x | 3 | 1 |
+------+----------------------+-----------------------------+

亲爱的上帝,为什么?

但更糟糕的是......

mysql> SELECT '3x', CAST('3z' as signed), '3x' = CAST('3z' as signed);
+----+----------------------+-----------------------------+
| 3x | CAST('3z' as signed) | '3x' = CAST('3z' as signed) |
+----+----------------------+-----------------------------+
| 3x | 3 | 1 |
+----+----------------------+-----------------------------+

为什么,哦,为什么?为什么它让我哭得这么......?

最佳答案

文档里都有:

http://dev.mysql.com/doc/refman/5.1/en/type-conversion.html

尤其是行

In all other cases, the arguments are compared as floating-point (real) numbers.

所以你所有的比较都是浮点比较,因此非常有意义。

人们可以争论自动类型转换是否有意义(是否可以将 '1' 与 1 进行比较?)...

关于mysql - 为什么是 MySQL ... 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23632896/

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