MySql like 查询 变向写法(不用like 完成like查询)
生活随笔
收集整理的這篇文章主要介紹了
MySql like 查询 变向写法(不用like 完成like查询)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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等開頭的數據。
轉載于:https://www.cnblogs.com/hoojo/archive/2011/10/27/2226676.html
總結
以上是生活随笔為你收集整理的MySql like 查询 变向写法(不用like 完成like查询)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ 并查集 题目汇总 ——czyua
- 下一篇: Andriod: 在xml布局中使用自定