威凡网全力打造:网页编程、软件开发编程、平面设计、服务器端开发、操作系统等在线学习平台!学编程,上威凡网!
数据库>> Mysql Sqlserver Oracle SQlite Access Sybase SQL其他
当前位置:首页 > 数据库 > Mysql
上一节 下一节
 mysql语句中使用like后面的%(百分号)的问题

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

  总用时:0.0489秒 0.0691 0.0485 0.0467

  select `goods_name`, `goods_img`, `sku_id`, `import` from `goods` where `goods_name` like '%iphone%ipod%' 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 '%iphone%' and `goods_name` like '%ipod%' 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 '%%%%%%%%%%%%%%%%%%%%%%%iphone%ipod%%%%%%%%%%%%%%%%%%%%%%%' and `stime` < 1413877997 and `etime` > 1413877997 order by `flag` desc

  实践证明,,百分号的数量不影响sql执行的速度。这几种方法的效率都是差不多的。

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


申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!
上一节 下一节
相关教程  
其他教程  
Mysql
Sqlserver
Oracle
SQlite
Access
Sybase
SQL其他

违法和不良信息举报中心】邮箱:254677821@qq.com
Copyright©威凡网 版权所有 苏ICP备2023020142号
站长QQ:254677821