Home >Database >Mysql Tutorial >mysql语句中使用like后面的%(百分号)的问题_MySQL

mysql语句中使用like后面的%(百分号)的问题_MySQL

WBOY
WBOYOriginal
2016-06-01 13:04:011461browse

问题:mysql语句中使用like后面的%(百分号) 是不是越多执行效率越慢!

总用时:0.0489秒 0.0691 0.0485 0.0467

SELECT `goods_name`, `goods_img`, `sku_id`, `import` FROM `goods` WHERE `goods_name` LIKE &#39;%iPhone%iPod%&#39; AND `stime` < 1413877244 AND `etime` > 1413877244 ORDER BY `flag` DESC
总用时:0.0460秒 0.0430 0.0493 0.0783 0.0496
SELECT `goods_name`, `goods_img`, `sku_id`, `import` FROM `goods` WHERE `goods_name` LIKE &#39;%iPhone%&#39; AND `goods_name` LIKE &#39;%iPod%&#39; AND `stime` < 1413877367 AND `etime` > 1413877367 ORDER BY `flag` DESC

总用时:0.0458秒 0.0441秒 0.0449秒

SELECT `goods_name`, `goods_img`, `sku_id`, `import` FROM `goods` WHERE `goods_name` LIKE &#39;%%%%%%%%%%%%%%%%%%%%%%%iPhone%iPod%%%%%%%%%%%%%%%%%%%%%%%&#39; AND `stime` < 1413877997 AND `etime` > 1413877997 ORDER BY `flag` DESC
实践证明,百分号的数量不影响sql执行的速度。这几种方法的效率都是差不多的。

以上是我测试的结果。个人可根据自己的实际需求去选择写法!建议是最好选择第二种!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn