我有一个有打印错误的查询:
SELECT
SUM(qty)
AS
'aqty1'
FROM
po_details
WHERE
product_id ='1196'
AND
so_number = '1m';
应该是:
SELECT
SUM(qty)
AS
'aqty1'
FROM
po_details
WHERE
product_id ='1196'
AND
so_number = '1';
但是第一个错误的 so_number = '1m'
神秘地输出正确,与第二个正确的查询输出相同的输出,这不应该是这种情况,对吧?
product_id
和so_number
的数据类型都是INT
。如果 so_number
的数据类型是 VARCHAR
,so_number = '1m'
应该有效,因为我已经包含了 1m
在引号内,条件集是 so_number LIKE '%1m%'
。
那么为什么上面的拼写错误查询有效? MySQL 不应该报错说找不到 1m
并将其视为 1
吗?这是一个已知的错误?我正在使用 MySQL 5.6.14。
截图如下:
最佳答案
它是隐式转换,由 MySQL 执行。你可以读到那个 here :
When an operator is used with operands of different types, type conversion occurs to make the operands compatible. Some conversions occur implicitly.
例如:
mysql> SELECT 1+'1';
-> 2
mysql> SELECT CONCAT(2,' test');
-> '2 test'
关于where子句中的MySQL错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46111500/