求助: 这个 SQL 查询如何写? 谢谢

2020-10-17 20:52:42 +08:00
 sprinter

查询输入表 A(单列单词串):

id String

1 As

2 soon

3 as

4 he

5 see

6 teacher

7 ,

8 he

9 say

10 "

11 good

12 morning

13 "

14 !

查询输入表 B(词组字典)

String

as soon as

good morning

as soon as

查询输出表 C(找出哪些行有什么词组)

id String

1 as soon as

2 as soon as

3 as soon as

11 good morning

12 good morning

请教各位,

请参阅上述 2 个表格: 我需要在单列单词串中找出词组(词组长度不一, 一般为 2~10 个单词). SQL 查询基于 A,B 表, 查询需输出 C 表, 这个 SQL 该如何写? 多谢指教!!

1333 次点击
所在节点    程序员
1 条回复
gaobing
2020-10-17 21:24:04 +08:00
select a.id, b.string from a join b on b.string like concat(a.string,' %') or b.string like concat('% ',a.string) or b.string like concat('% ',a.string,' %')

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/715990

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX