使用sqlserver从数据库中获取最接近的值 [英] to get only the closest value from database using sqlserver

查看:285
本文介绍了使用sqlserver从数据库中获取最接近的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







我在文本框中输入了值,如果我在单词中输入错误的拼写我想得到结果来自与该搜索值最接近的数据库







例如





而不是Hyderabad正在搜索'Hydearbad'这是错误的拼写我想从数据库中获得建议最接近的匹配

Hi,


I entered the value in a textbox if i give wrong spelling in the word i want to get the result from datbase which the closest matching to that search value



for example


Instead of Hyderabad is search for 'Hydearbad' which is wrong spelt i want to get suggestions from database only closest matching

推荐答案

请注意,这不是微不足道的,甚至不是轻微的!

您正在考虑实现模糊匹配,它不是内置于SQL中,通常使用< a href =http://en.wikipedia.org/wiki/Levenshtein_distance> Levenshtein距离算法 [ ^ ] - 这里有一个实现: http://www.kodyaz.com/articles/fuzzy-string-matching-using-levenshtein-distance-sql-server.aspx [ ^ ]然后按最低顺序排列所有可能的字符串LD值 - LD越高,两个字符串越不同。



不要指望它快速运行,并且不要指望它很简单实行! :笑:
Be aware that this is not trivial, not even slightly!
You are looking at implementing "Fuzzy Matching" which is not built in to SQL and is often implemented using the Levenshtein Distance algorithm[^] - there is an implementation of that here: http://www.kodyaz.com/articles/fuzzy-string-matching-using-levenshtein-distance-sql-server.aspx[^] and then ordering all "possible" strings by lowest LD value - the higher the LD, the more different two strings are.

Don't expect it to run quickly, and don't expect it to be simple to implement! :laugh:


几年前我问类似问题 [ ^ ]。

请访问它并找到解决方案。
Few years ago i asked similar question[^].
Please, visit it and find out the solution for you.


这篇关于使用sqlserver从数据库中获取最接近的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆