V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sprinter
V2EX  ›  程序员

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

  •  
  •   sprinter · 2020-10-17 20:52:42 +08:00 · 1327 次点击
    这是一个创建于 1278 天前的主题,其中的信息可能已经有所发展或是发生改变。

    查询输入表 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 该如何写? 多谢指教!!

    1 条回复    2020-10-17 21:24:04 +08:00
    gaobing
        1
    gaobing  
       2020-10-17 21:24:04 +08:00 via Android   ❤️ 1
    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,' %')
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3444 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.