【发布时间】:2026-01-08 23:15:02
【问题描述】:
我有一个表格“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,' ','\',\''),'\'')))
我有超过 50 万行数据要处理,所以我宁愿只使用 MySQL,而不使用任何 PHP。
如果您有解决方案,请提前致谢!
我希望 MySQL 中有一个 explode() 函数!
【问题讨论】:
标签: mysql dynamic split explode