Mysql 其中smallInteger等于字符串返回结果

Mysql 其中smallInteger等于字符串返回结果,mysql,sql,database,conditional-statements,where-clause,Mysql,Sql,Database,Conditional Statements,Where Clause,我有一个带有smallInteger列的表,有两条记录作为零值 如果我运行以下查询,则返回结果: select `status` from users where `status` = 'confirmed' 怎么可能 实际上,任何字符串都会返回此记录。mysql将把CHAR值转换为SMALLINT,因为'confirm'不是数字,它将返回0 因此:0='confirmed'被解释为这个0=CAST('confirmed as SMALLINT),它的计算结果是0=0 因此,当列status

我有一个带有smallInteger列的表,有两条记录作为零值

如果我运行以下查询,则返回结果:

select `status` from users where `status` = 'confirmed'
怎么可能


实际上,任何字符串都会返回此记录。

mysql将把
CHAR
值转换为
SMALLINT
,因为
'confirm'
不是数字,它将返回
0

因此:
0='confirmed'
被解释为这个
0=CAST('confirmed as SMALLINT)
,它的计算结果是
0=0


因此,当列
status
0
时,它等于
'confirmed'
,因为
SMALLINT

非数字字符串只能转换为0。你预期会发生什么?仔细研究: