Skip to content

Instantly share code, notes, and snippets.

@fasthold
Created March 8, 2011 08:51
Show Gist options
  • Save fasthold/860049 to your computer and use it in GitHub Desktop.
Save fasthold/860049 to your computer and use it in GitHub Desktop.
简易模糊查询 按相关性排序 SQL语句
SELECT * , IF( `Word` = 'sim', 1, IF( `Word` LIKE 'sim%', 2, IF( `Word` LIKE '%sim', 4, 3 ) ) ) AS `sort` FROM `dblist` WHERE `Word` LIKE '%sim%' ORDER BY `sort` , `Word`
# 得到结果:
1. sim
2. sim*
3. *sim*
4. sim*
@fasthold
Copy link
Author

fasthold commented Mar 8, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment