我有一个表格“wordlist”,每个单词都有一个分数:1或-1:
id | name | val
1, 'hello', 1,
2, 'world', -1
3, 'test', 1,
...
我还有一个包含文本的表格“文本”:
id | text | score
1, 'hello world', 0
2, 'Lorem Ipsum Dolor Sit Amet...', 0
...
我想使用以下规则更新表“文本”中的“分数”字段:
score = sum(wordlist.val) 其中句子的每个单词都存在于单词列表中。
我试过这种方式,但它不起作用:
update texts as t set score=(select sum(val) from wordlist where word in (concat('\'', replace(t.text,' ','\',\''),'\'')))
我有超过 500K 行数据要处理,所以我宁愿只使用 MySQL,而不使用任何 PHP。
如果您有解决方案,请提前致谢!
我希望 MySQL 中有一个 explode() 函数!