对于选择 0='a', 0='';
1. type of 0 is int
2. type of 'a' is char then CAST( 'a' AS UNSIGNED ) or CAST( '' AS UNSIGNED ) will be 0
将 char 转换为 int 然后 0=0 在您的情况 1 中评估为 true。在:
select 'A'='a', 0=0, '0'='a',0='a1';
所有列都为真,但对于:
select 0='1a';
将是错误的,因为 CAST('1a' AS UNSIGNED) 为 1。
mysql> SELECT 'asadsadsa' = 'a', 0 = 'az', cast( 'az' AS unsigned ) , 'asadsadsa' = 'a' = 'az', 0 =0;
+-------------------+----------+--------------------------+--------------------------+------+
| 'asadsadsa' = 'a' | 0 = 'az' | cast( 'az' AS unsigned ) | 'asadsadsa' = 'a' = 'az' | 0 =0 |
+-------------------+----------+--------------------------+--------------------------+------+
| 0 | 1 | 0 | 1 | 1 |
+-------------------+----------+--------------------------+--------------------------+------+
1 row in set, 3 warnings (0.00 sec)
Warning (Code 1292): Truncated incorrect DOUBLE value: 'az'
Warning (Code 1292): Truncated incorrect INTEGER value: 'az'
Warning (Code 1292): Truncated incorrect DOUBLE value: 'az'