MySQL中比like语句更高效的写法locate position instr find_in_set
来源:互联网 发布:mac怎么导入手机照片 编辑:程序博客网 时间:2024/04/30 05:05
你是否一直在寻找比MySQL的LIKE语句更高效的方法的,下面我就为你介绍几种。
LIKE语句
SELECT `column` FROM `table` where `condition` like`%keyword%'
事实上,可以使用 locate(position) 和 instr这两个函数来代替
LOCATE语句
SELECT `column` from `table` where locate(‘keyword’,`condition`)>0
或是 locate 的別名 position
POSITION语句
SELECT `column` from `table` where position(‘keyword’ IN`condition`)
或是
INSTR语句
SELECT `column` from `table` where instr(`condition`, ‘keyword’)>0
locate、position 和 instr 的差別只是参数的位置不同,同时locate多一个起始位置的参数外,两者是一样的。
mysql> SELECT LOCATE(‘bar’, ‘foobarbar’,5);
-> 7
速度上这三个比用 like 稍快了一点。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽的分割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
还要给大家介绍一个新成员,那就是find_in_set
LIKE语句
SELECT `column` FROM `table` where `condition` like`%keyword%'
事实上,可以使用 locate(position) 和 instr这两个函数来代替
LOCATE语句
SELECT `column` from `table` where locate(‘keyword’,`condition`)>0
或是 locate 的別名 position
POSITION语句
SELECT `column` from `table` where position(‘keyword’ IN`condition`)
或是
INSTR语句
SELECT `column` from `table` where instr(`condition`, ‘keyword’)>0
locate、position 和 instr 的差別只是参数的位置不同,同时locate多一个起始位置的参数外,两者是一样的。
mysql> SELECT LOCATE(‘bar’, ‘foobarbar’,5);
-> 7
速度上这三个比用 like 稍快了一点。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~华丽的分割线~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
还要给大家介绍一个新成员,那就是find_in_set
find_in_set(str1,str2) 函数:返回str2中str1所在的位置索引,其中str2必须以","分割开。表:mysql> select * from region;+----+-------------+| id | name |+----+-------------+| 1 | name1,nam2 || 2 | name1 || 3 | name3 || 4 | name2,name4 || 5 | name3,name5 |+----+-------------+5 rows in set (0.00 sec)FIND_IN_SET语句mysql> select * from test where find_in_set('name1',name);+----+------------+| id | name |+----+------------+| 1 | name1,nam2 || 2 | name1 |+----+------------+2 rows in set (0.02 sec)谢谢关注websites博客.
1 0
- MySQL中比like语句更高效的写法locate position instr find_in_set
- MySQL中比like语句更高效的写法locate position instr find_in_set
- MySQL中比like语句更高效的写法locate position instr find_in_set
- MySQL中比like语句更高效的写法locate/position/instr/find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL比like语句更高效的写法locate、position、instr find_in_set
- MySQL比like语句更高效的写法locate position instr find_in_set
- MySQL:比like语句更高效的写法locate position instr find_in_set(2014-05-07 17:40:04)
- mysql中比like更高效的查询find_in_set
- mysql 模糊查询语句比较(LIKE、instr、locate、find_in_set、position)
- MySQL比like语句更高效的写法
- 谈一谈MySQL的LOCATE、FIND_IN_SET、INSTR、POSITION的差别
- SQL之查询函数LOCATE、POSITION、INSTR、FIND_IN_SET、IN、LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- Mysql函数INSTR、LOCATE、POSITION VS LIKE
- wifi断线问题
- SDK编译数学函数出错:"undefined reference to 'cos/sin'
- 建模语言的概念 与编程语言概念对应关系(入门必读)
- 写给我们这些浮躁的程序员
- android:inputType参数类型说明
- MySQL中比like语句更高效的写法locate position instr find_in_set
- .NET 查看 EF 查询生成的SQL 语句
- 【Java基础面试题】【01】
- Run-time error ‘339’
- Linux 查看线程
- 二级菜单关联
- 在公司局域网内安装无线路由器的连接设置方法
- OpenCL概述
- 黑马程序员---泛型实例创建的类型推断