Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张包含以下数据的表格
表事务
trasaction_id 886 456 654_asd 898_ASDF
如果我用这些句子
SELECT trasaction_id from transactions where transaction_id IN (886,654)
我希望结果是886,
886
但是mysql正在返回886,654_ASDF
886,654_ASDF
为什么654_ASDF在该查询中返回?
654_ASDF
发生这种情况是因为transaction_id它是一个字符串,但您的比较值是数字。因此,transaction_id正在使用“静默转换”将其转换为数字。这意味着不报告错误。
transaction_id
转换并没有真正使用like. 它通过将字符串的前导字符转换为数字(如果它们看起来像数字)来进行。忽略后续字符。
like
因此,只需使用正确的类型:
SELECT trasaction_id FROM transactions WHERE transaction_id IN ('886', '654');