select * from account where userName like 'ad%';
select * from account where userName >= 'ad' and userName < 'ae';
/*
這兩種查詢的結(jié)果是一樣的,效率好像也差不多,沒(méi)有做具體的效率測(cè)試,有興趣可以測(cè)試下效率。
like查詢中的ad%是查詢ad開(kāi)頭userName的數(shù)據(jù),
而userName >= 'ad'就是查詢ad開(kāi)頭的數(shù)據(jù)并且還包含 ae、af、ag……,也就是說(shuō)是查詢“ad”中包含d且大于“ad”中d的數(shù)據(jù)
所以,and userName < 'ad'就保證查詢的區(qū)間在“ad”中的,而ae、af、ag……這些數(shù)據(jù)就不會(huì)出現(xiàn)在結(jié)果集中。
當(dāng)然你可以試試:
select * from account where userName >= 'ad' and userName < 'az';
結(jié)果集是不是包含:ae、af、ag……ak、al……ay、az等開(kāi)頭的數(shù)據(jù)。
*/
select * from account where userName >= 'ad' and userName < 'ae';
/*
這兩種查詢的結(jié)果是一樣的,效率好像也差不多,沒(méi)有做具體的效率測(cè)試,有興趣可以測(cè)試下效率。
like查詢中的ad%是查詢ad開(kāi)頭userName的數(shù)據(jù),
而userName >= 'ad'就是查詢ad開(kāi)頭的數(shù)據(jù)并且還包含 ae、af、ag……,也就是說(shuō)是查詢“ad”中包含d且大于“ad”中d的數(shù)據(jù)
所以,and userName < 'ad'就保證查詢的區(qū)間在“ad”中的,而ae、af、ag……這些數(shù)據(jù)就不會(huì)出現(xiàn)在結(jié)果集中。
當(dāng)然你可以試試:
select * from account where userName >= 'ad' and userName < 'az';
結(jié)果集是不是包含:ae、af、ag……ak、al……ay、az等開(kāi)頭的數(shù)據(jù)。
*/
作者:hoojo
出處:
blog:http://blog.csdn.net/IBM_hoojo
http://hoojo.cnblogs.com
本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利。
版權(quán)所有,轉(zhuǎn)載請(qǐng)注明出處 本文出自:
