久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='LF3x5'></tfoot>

      <small id='LF3x5'></small><noframes id='LF3x5'>

        <bdo id='LF3x5'></bdo><ul id='LF3x5'></ul>

      1. <legend id='LF3x5'><style id='LF3x5'><dir id='LF3x5'><q id='LF3x5'></q></dir></style></legend>
        <i id='LF3x5'><tr id='LF3x5'><dt id='LF3x5'><q id='LF3x5'><span id='LF3x5'><b id='LF3x5'><form id='LF3x5'><ins id='LF3x5'></ins><ul id='LF3x5'></ul><sub id='LF3x5'></sub></form><legend id='LF3x5'></legend><bdo id='LF3x5'><pre id='LF3x5'><center id='LF3x5'></center></pre></bdo></b><th id='LF3x5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LF3x5'><tfoot id='LF3x5'></tfoot><dl id='LF3x5'><fieldset id='LF3x5'></fieldset></dl></div>

        SQL 函數 - 使用 Levenshtein 距離算法進行模糊匹配

        SQL Function - Fuzzy Matching with Levenshtein Distance Algorithm - Return Lowest Value Only(SQL 函數 - 使用 Levenshtein 距離算法進行模糊匹配 - 僅返回最低值)
        <tfoot id='PGBlV'></tfoot>
            <bdo id='PGBlV'></bdo><ul id='PGBlV'></ul>

          • <legend id='PGBlV'><style id='PGBlV'><dir id='PGBlV'><q id='PGBlV'></q></dir></style></legend>

              1. <small id='PGBlV'></small><noframes id='PGBlV'>

                <i id='PGBlV'><tr id='PGBlV'><dt id='PGBlV'><q id='PGBlV'><span id='PGBlV'><b id='PGBlV'><form id='PGBlV'><ins id='PGBlV'></ins><ul id='PGBlV'></ul><sub id='PGBlV'></sub></form><legend id='PGBlV'></legend><bdo id='PGBlV'><pre id='PGBlV'><center id='PGBlV'></center></pre></bdo></b><th id='PGBlV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PGBlV'><tfoot id='PGBlV'></tfoot><dl id='PGBlV'><fieldset id='PGBlV'></fieldset></dl></div>
                  <tbody id='PGBlV'></tbody>

                  本文介紹了SQL 函數 - 使用 Levenshtein 距離算法進行模糊匹配 - 僅返回最低值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  問題:需要 SQL 函數使用 Levenshtein 算法返回最低"匹配值.

                  代碼:

                  <預><代碼>創建函數 ufn_levenshtein(@s1 nvarchar(3999), @s2 nvarchar(3999))返回整數作為開始聲明 @s1_len int, @s2_len int聲明 @i int、@j int、@s1_char nchar、@c int、@c_temp int聲明@cv0 varbinary(8000), @cv1 varbinary(8000)選擇@s1_len = LEN(@s1),@s2_len = LEN(@s2),@cv1 = 0x0000,@j = 1,@i = 1,@c = 0而@j <= @s2_lenSELECT @cv1 = @cv1 + CAST(@j AS binary(2)),@j = @j + 1當@i <= @s1_len開始選擇@s1_char = SUBSTRING(@s1, @i, 1),@c = @i,@cv0 = CAST(@i AS binary(2)),@j = 1當@j <= @s2_len開始設置@c = @c + 1SET @c_temp = CAST(SUBSTRING(@cv1, @j+@j-1, 2) AS int) +當@s1_char = SUBSTRING(@s2, @j, 1) THEN 0 ELSE 1 END如果@c >@c_temp SET @c = @c_tempSET @c_temp = CAST(SUBSTRING(@cv1, @j+@j+1, 2) AS int)+1如果@c >@c_temp SET @c = @c_tempSELECT @cv0 = @cv0 + CAST(@c AS binary(2)),@j = @j + 1結尾選擇@cv1 = @cv0,@i = @i + 1結尾返回@c結尾如果 OBJECT_ID('tempdb..#ExistingCustomers') 不是 NULL刪除表#ExistingCustomers;創建表#ExistingCustomers(客戶 VARCHAR(255),身份證號碼)INSERT #ExistingCustomers SELECT 'Ed''s Barbershop', 1002INSERT #ExistingCustomers SELECT 'GroceryTown', 1003INSERT #ExistingCustomers SELECT 'Candy Place', 1004INSERT #ExistingCustomers SELECT 'Handy Man', 1005如果 OBJECT_ID('tempdb..#POTENTIALCUSTOMERS') 不是 NULL下降表#潛在客戶;創建表#POTENTIALCUSTOMERS(客戶VARCHAR(255));插入 #POTENTIALCUSTOMERS SELECT 'Eds Barbershop'INSERT #POTENTIALCUSTOMERS SELECT '雜貨城'插入 #POTENTIALCUSTOMERS 選擇糖果店"INSERT #POTENTIALCUSTOMERS SELECT 'Handee Man'插入 #POTENTIALCUSTOMERS 選擇蘋果農場"插入 #POTENTIALCUSTOMERS SELECT 'Ride-a-Long Bikes'選擇 A. 客戶,出價,b.客戶作為客戶,dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) 作為 ValueLev來自#POTENTIALCUSTOMERS aLEFT JOIN #ExistingCustomers b ON dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) <15;

                  返回:

                  我想退貨:

                  說明:結果是 Levenshtein 算法的最低"值.有兩行 Levenshtein 分數相同 The Apple FarmRide-a-Long Bikes,在這種情況下,任何值都可以,只要它是一種價值.

                  參考資料:

                  SQL 模糊連接 - MSSQL

                  http://www.kodyaz.com/articles/fuzzy-string-matching-using-levenshtein-distance-sql-server.aspx

                  解決方案

                  如果您按潛在客戶進行分區并使用 ValueLev 對結果進行排序,則可以使用 CTE 來獲得您想要的結果:

                  ;with CTE AS(SELECT RANK() OVER (PARTITION BY a.Customer ORDER BY dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) ASC) AS RowNbr,一個客戶,出價,b.客戶作為客戶,dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) 作為 ValueLev來自#POTENTIALCUSTOMERS aLEFT JOIN #ExistingCustomers b ON dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) <15)選擇客戶,MIN(ID) 作為 ID,MIN(cust) AS cust,價值等級從 CTE哪里 CTE.RowNbr = 1按客戶分組,ValueLev

                  由于您不介意在重復 ValueLev 的情況下返回哪個結果,請使用 GROUP BYMIN 來縮放結果每個潛在客戶最多一個.

                  輸出:

                  Customer ID cust ValueLev糖果店 1004 糖果店 0雜貨鎮 1003 雜貨鎮 0Eds 理發店 1002 Ed 的理發店 1勤雜工 1005 勤雜工 2蘋果農場 1004 Candy Place 9Ride-a-Long Bikes 1003 Candy Place 14

                  Problem: Need SQL function to return the 'lowest' matching value using the Levenshtein algorithm.

                  Code:

                  
                  CREATE FUNCTION ufn_levenshtein(@s1 nvarchar(3999), @s2 nvarchar(3999))
                  RETURNS int
                  AS
                  BEGIN
                   DECLARE @s1_len int, @s2_len int
                   DECLARE @i int, @j int, @s1_char nchar, @c int, @c_temp int
                   DECLARE @cv0 varbinary(8000), @cv1 varbinary(8000)
                  
                   SELECT
                    @s1_len = LEN(@s1),
                    @s2_len = LEN(@s2),
                    @cv1 = 0x0000,
                    @j = 1, @i = 1, @c = 0
                  
                   WHILE @j <= @s2_len
                    SELECT @cv1 = @cv1 + CAST(@j AS binary(2)), @j = @j + 1
                  
                   WHILE @i <= @s1_len
                   BEGIN
                    SELECT
                     @s1_char = SUBSTRING(@s1, @i, 1),
                     @c = @i,
                     @cv0 = CAST(@i AS binary(2)),
                     @j = 1
                  
                    WHILE @j <= @s2_len
                    BEGIN
                     SET @c = @c + 1
                     SET @c_temp = CAST(SUBSTRING(@cv1, @j+@j-1, 2) AS int) +
                      CASE WHEN @s1_char = SUBSTRING(@s2, @j, 1) THEN 0 ELSE 1 END
                     IF @c > @c_temp SET @c = @c_temp
                     SET @c_temp = CAST(SUBSTRING(@cv1, @j+@j+1, 2) AS int)+1
                     IF @c > @c_temp SET @c = @c_temp
                     SELECT @cv0 = @cv0 + CAST(@c AS binary(2)), @j = @j + 1
                   END
                  
                   SELECT @cv1 = @cv0, @i = @i + 1
                   END
                  
                   RETURN @c
                  END
                  
                  
                  
                  
                  IF OBJECT_ID('tempdb..#ExistingCustomers') IS NOT NULL
                      DROP TABLE #ExistingCustomers;
                  
                      CREATE TABLE #ExistingCustomers
                  (
                      Customer VARCHAR(255),
                      ID INT
                  )
                  
                  INSERT #ExistingCustomers SELECT 'Ed''s Barbershop',  1002
                  INSERT #ExistingCustomers SELECT 'GroceryTown',  1003
                  INSERT #ExistingCustomers SELECT 'Candy Place',  1004
                  INSERT #ExistingCustomers SELECT 'Handy Man',  1005
                  
                  
                  
                  IF OBJECT_ID('tempdb..#POTENTIALCUSTOMERS') IS NOT NULL
                      DROP TABLE #POTENTIALCUSTOMERS;
                  
                  CREATE TABLE #POTENTIALCUSTOMERS(Customer VARCHAR(255));
                  
                  INSERT #POTENTIALCUSTOMERS SELECT 'Eds Barbershop'
                  INSERT #POTENTIALCUSTOMERS SELECT 'Grocery Town'
                  INSERT #POTENTIALCUSTOMERS SELECT 'Candy Place'
                  INSERT #POTENTIALCUSTOMERS SELECT 'Handee Man'
                  INSERT #POTENTIALCUSTOMERS SELECT 'The Apple Farm'
                  INSERT #POTENTIALCUSTOMERS SELECT 'Ride-a-Long Bikes'
                  
                  
                  SELECT A.Customer,
                         b.ID,
                         b.Customer as cust,
                         dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) as ValueLev
                  FROM #POTENTIALCUSTOMERS a
                       LEFT JOIN #ExistingCustomers b ON dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) < 15;
                  
                  

                  This returns:

                  What I would like to return:

                  Explanation: The results are the 'lowest' values from the Levenshtein algorithm. There are two rows where the Levenshtein scores are the same The Apple Farm and Ride-a-Long Bikes, in which case any of the values is fine, just as long as it is one value.

                  References:

                  SQL Fuzzy Join - MSSQL

                  http://www.kodyaz.com/articles/fuzzy-string-matching-using-levenshtein-distance-sql-server.aspx

                  解決方案

                  You can use CTE to get the result you want if you partition by the potential customer and use the ValueLev to order the results:

                  ;WITH CTE AS
                  (
                      SELECT  RANK() OVER (PARTITION BY a.Customer ORDER BY dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) ASC) AS RowNbr,
                              A.Customer,
                              b.ID,
                              b.Customer as cust,
                              dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) as ValueLev
                        FROM  #POTENTIALCUSTOMERS a
                          LEFT JOIN #ExistingCustomers b ON dbo.ufn_levenshtein(REPLACE(A.Customer, ' ', ''), REPLACE(B.Customer, ' ', '')) < 15
                  )
                  SELECT  Customer,
                          MIN(ID) AS ID,
                          MIN(cust) AS cust,
                          ValueLev
                    FROM  CTE
                    WHERE CTE.RowNbr = 1
                    GROUP BY Customer, ValueLev
                  

                  As you don't mind which result is returned in the case of duplicate ValueLev, use GROUP BY and MIN to scale the results down to one per potential customer.

                  Output:

                  Customer            ID      cust            ValueLev
                  Candy Place         1004    Candy Place     0
                  Grocery Town        1003    GroceryTown     0
                  Eds Barbershop      1002    Ed's Barbershop 1
                  Handee Man          1005    Handy Man       2
                  The Apple Farm      1004    Candy Place     9
                  Ride-a-Long Bikes   1003    Candy Place     14
                  

                  這篇關于SQL 函數 - 使用 Levenshtein 距離算法進行模糊匹配 - 僅返回最低值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  SQL query to get all products, categories and meta data woocommerce/wordpress(獲取所有產品、類別和元數據的 SQL 查詢 woocommerce/wordpress)
                  Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數據庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發
                  How to create a login to a SQL Server instance?(如何創建對 SQL Server 實例的登錄?)
                  How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                  Why do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(為什么會出現“數據類型轉換錯誤?使用 ExecuteNonQuery()?)
                  How to show an image from a DataGridView to a PictureBox?(如何將 DataGridView 中的圖像顯示到 PictureBox?)
                    <tbody id='J74jT'></tbody>

                  <tfoot id='J74jT'></tfoot>

                      • <small id='J74jT'></small><noframes id='J74jT'>

                          <legend id='J74jT'><style id='J74jT'><dir id='J74jT'><q id='J74jT'></q></dir></style></legend>
                          <i id='J74jT'><tr id='J74jT'><dt id='J74jT'><q id='J74jT'><span id='J74jT'><b id='J74jT'><form id='J74jT'><ins id='J74jT'></ins><ul id='J74jT'></ul><sub id='J74jT'></sub></form><legend id='J74jT'></legend><bdo id='J74jT'><pre id='J74jT'><center id='J74jT'></center></pre></bdo></b><th id='J74jT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='J74jT'><tfoot id='J74jT'></tfoot><dl id='J74jT'><fieldset id='J74jT'></fieldset></dl></div>
                          • <bdo id='J74jT'></bdo><ul id='J74jT'></ul>
                            主站蜘蛛池模板: 久久精品欧美一区二区三区麻豆 | 在线免费观看黄视频 | 欧美精品导航 | 免费精品 | 免费在线观看h片 | 亚洲国产精品一区二区三区 | 瑟瑟视频在线看 | 久久av资源网 | 国产精品久久午夜夜伦鲁鲁 | 日韩成人在线网址 | 国产成人网 | 国产美女永久免费无遮挡 | 日韩福利在线观看 | 久久精品亚洲精品 | 欧美综合久久 | 久久99精品国产自在现线小黄鸭 | 中文字幕日韩欧美一区二区三区 | 久草网站| 国产一区二区在线观看视频 | 亚洲视频一区 | 国产精品久久777777 | 欧美日韩国产三级 | 久久久影院| 狠狠草视频| 国产福利91精品一区二区三区 | 久久国产成人 | 99re6在线视频 | 欧美色成人 | 性福视频在线观看 | 网站黄色在线 | 国产美女自拍视频 | 国产在线麻豆精品入口 | 亚洲乱码一区二区三区在线观看 | 国产精品1区2区 | 亚洲国产高清免费 | 久久国产视频网 | 狠狠狠色丁香婷婷综合久久五月 | 一区二区三区免费 | 狠狠亚洲| 久久精品国产久精国产 | 亚州精品成人 |