我有两个表:TableA:id,StringA TableB:id,StringB
从TableA中获取所有行后,我希望匹配尽可能接近TableB中的单词.我正在尝试做这样的事情:
c.execute('SELECT id, StringB FROM TableB WHERE StringB LIKE "'+stringa+'%" COLLATE NOCASE') foundrows=c.fetchall() if (len(foundrows)>0): print 'Hmm. Which one...' for foundrow in foundrows: print 'looking for:'+stringa+' found:'+ foundrow[1]
哪个给我这样的东西:
Hmm. Which one... looking for:goo found:good looking for:goo found:good 1 looking for:goo found:good 2 looking for:goo found:good 1 dk looking for:goo found:good 2 dk looking for:goo found:Good Friday looking for:goo found:goose looking for:goo found:Good Friday 1 looking for:goo found:good sport looking for:goo found:good job looking for:goo found:good morning looking for:goo found:good night looking for:goo found:goodbye 1 looking for:goo found:goodbye e looking for:goo found:goodbye
我真正想要的是'SELECT id,StringB FROM TableB WHERE StringB CONTAINS WORD"'+ stringa +'"
什么是实现"包含Word"的最佳方式?
构建一个这样的where子句:
where (' ' || StringB || ' ') LIKE '% stringa %'
周围的空格StringB
确保您在字符串的开头和结尾处捕获单词.