【问题标题】:Where smallInteger equal to string return result [closed]其中smallInteger等于字符串返回结果[关闭]
【发布时间】:2020-12-29 00:09:25
【问题描述】:

我有一个包含 smallInteger 列的表,其中 2 条记录为零值。

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

select `status` from users where `status` = 'confirmed'

怎么可能?

其实任何字符串都会返回这条记录。

【问题讨论】:

标签: mysql sql database conditional-statements where-clause


【解决方案1】:

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

所以这个:0 = 'confirmed' 被解释为这个0 = CAST('confirmed as SMALLINT)',其计算结果为0 = 0

所以当status 列是0 时,它等于'confirmed' 作为SMALLINT

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 2016-02-20
    相关资源
    最近更新 更多