gpt4 book ai didi

mysql - 按顺序检索包含单词的不同句子

转载 作者:行者123 更新时间:2023-11-30 22:48:16 25 4
gpt4 key购买 nike

使用 MySQL,如果您有一个句子表和一个单词表以及一个包含它们之间关系的多对多表,您将如何构建查询以查找包含短语的句子?

例如,使用这些表...

Words
1 apples
2 like
3 I
4 used
5 to
6 eat

Sentences
1 I used to like apples
2 I used to eat apples

Words2Sentences
pkey fk_word fk_sentence
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
6 1 2
7 3 2
8 4 2
9 5 2
10 6 2

您将如何构建连接和查询以找到短语“used to”。由于多语言支持要求,全文索引无法满足我的需求。

最佳答案

WHERE 子句中使用 INNER JOINLIKE。见下文:

SELECT 
Words,Sentences
FROM Words A
INNER JOIN Words2Sentences B A.fk_word=B.fk_word
INNER JOIN Sentences C B.fk_sentence=C.fk_sentence
WHERE Sentences LIKE '%used to%'

关于mysql - 按顺序检索包含单词的不同句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28909991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com