select * from abc as t where t.num = 8898 order by t.create_dt
select * from abc as t where t.num like '8898' order by t.create_dt
select * from abc as t where t.num like reverse('%8898') order by t.create_dt
哪一个最快?最小化输出结果的耗时
select * from abc as t where t.num = 8898 order by t.create_dt
select * from abc as t where t.num like '8898' order by t.create_dt
select * from abc as t where t.num like reverse('%8898') order by t.create_dt
哪一个最快?最小化输出结果的耗时
我会说,这将是更快
select * from abc as t where t.num = 8898 order by t.create_dt
这是为什么?
您正在比较整数,但其他两种方法实际上是比较一个字符。
这种方法是错误的,但实际上它是可用:
select * from abc as t where t.num like '8898' order by t.create_dt
LIKE通常用于在数据库中的字符串或varchar。
这种方法也是错误的,但它也可用:
select * from abc as t where t.num like reverse('%8898') order by t.create_dt
对于整数,最好使用=,=!,>,<,>=,<=
至于字符串,它建议使用LIKE查找包含你的值完全匹配的字符串正在寻找。如果你想使用通配符来查找特定的字符串,可以这样使用:LIKE '%something%'
假设num
是一个数字,第一个应该不会慢于其他的。它可以从abc(num, create_dt)
索引中受益。
第二个可能会很快,除了它会将num
转换为字符串。如果没有索引,这与第一个不同。但是,这可能会阻止使用索引。
第三个是几乎相同的推理。
测试它们并查看哪些数据和系统中速度最快。 –