的字符匹配的百分比比方說,我有一組2個字:T-SQL獲得2串
亞歷山大和Alecsander OR亞歷山大和Alegzander
亞歷山大和Aleaxnder,或任何其他組合。總的來說,我們在談論輸入單詞或單詞時出現人爲錯誤。
我想要達到的是獲得兩個字符串的字符匹配的百分比。
這是我到目前爲止有:
DECLARE @table1 TABLE
(
nr INT
, ch CHAR
)
DECLARE @table2 TABLE
(
nr INT
, ch CHAR
)
INSERT INTO @table1
SELECT nr,ch FROM [dbo].[SplitStringIntoCharacters] ('WORD w') --> return a table of characters(spaces included)
INSERT INTO @table2
SELECT nr,ch FROM [dbo].[SplitStringIntoCharacters] ('WORD 5')
DECLARE @resultsTable TABLE
(
ch1 CHAR
, ch2 CHAR
)
INSERT INTO @resultsTable
SELECT DISTINCt t1.ch ch1, t2.ch ch2 FROM @table1 t1
FULL JOIN @table2 t2 ON t1.ch = t2.ch --> returns both matches and missmatches
SELECT * FROM @resultsTable
DECLARE @nrOfMathches INT, @nrOfMismatches INT, @nrOfRowsInResultsTable INT
SELECT @nrOfMathches = COUNT(1) FROM @resultsTable WHERE ch1 IS NOT NULL AND ch2 IS NOT NULL
SELECT @nrOfMismatches = COUNT(1) FROM @resultsTable WHERE ch1 IS NULL OR ch2 IS NULL
SELECT @nrOfRowsInResultsTable = COUNT(1) FROM @resultsTable
SELECT @nrOfMathches * 100/@nrOfRowsInResultsTable
的SELECT * FROM @resultsTable
將返回以下內容:
ch1 ch2
NULL 5
[blank] [blank]
D D
O O
R R
W W
它有什麼問題?該代碼工作正確嗎? – 2011-12-15 11:12:25
這是不準確的。 – 2011-12-15 12:10:56