加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 数据库 > MySql > 正文

MySql like 查询 变向写法(不用like 完成like查询)

发布时间:2020-05-27 08:36:48 所属栏目:MySql 来源:互联网
导读:select * from account where userName like ad%;select * from account where userName = ad and userName ae这两种查询的结果是一样的,效率好像也差不多,没有做具体的效率测试,有兴趣可以测试下效率。like查询中的ad%是查询ad开头userName的数据,而user

<div class="cnblogs_Highlighter">
<pre class="brush:sql;gutter:false;">select from account where userName like 'ad%';
select
from account where userName >= 'ad' and userName < 'ae'

这两种查询的结果是一样的,效率好像也差不多,没有做具体的效率测试,有兴趣可以测试下效率。

like查询中的ad%是查询ad开头userName的数据,

而userName >= 'ad'就是查询ad开头的数据并且还包含 ae、af、ag……,也就是说是查询“ad”中包含d且大于“ad”中d的数据

所以,and userName < 'ad'就保证查询的区间在“ad”中的,而ae、af、ag……这些数据就不会出现在结果集中。

当然你可以试试:

select * from account where userName >= 'ad' and userName < 'az';

结果集是不是包含:ae、af、ag……ak、al……ay、az等开头的数据。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读