gpt4 book ai didi

mysql - 如何在单词的SQL数据库中查询短语?

转载 作者:可可西里 更新时间:2023-11-01 08:39:01 31 4
gpt4 key购买 nike

我正在使用 MySQL 并且我有一个歌曲的 SQL 数据库,其中包含一个包含 8 列歌曲歌词信息的表格。每行代表歌曲歌词中的一个单词:

  1. songSerial - 歌曲的序号

  2. songName - 歌曲名称

  3. word - 歌曲歌词中的一个单词

  4. row_number - 找到单词的行号

  5. word_position_in_row - 单独行中的单词数

  6. house_number - 这个词所属的房子的编号

  7. house_row - 单词所在房屋的行号

  8. word_number - 所有歌曲歌词中的单词数

一行示例:{ 4 , The Scientist , secrets , 8 , 4 , 2 , 1 , 37 }

现在我想查询所有包含一组词的歌曲。例如所有带有句子的单词:“我爱你”。 必须按此顺序,而不是来自不同的行或房子。

这是我的 oneDrive 中用于创建数据表和大约 400 行的脚本: TwoTextScriptFilesAndTheirZip

有人能帮忙吗?

谢谢

最佳答案

一种方法是使用join:

select s.*
from songwords sw1 join
songwords sw2
on sw2.songSerial = sw1.songSerial and
sw2.word_number = sw1.word_number + 1 join
songwords sw3
on sw3.songSerial = sw2.songSerial and
sw3.word_number = sw2.word_number + 1
where sw1.word = 'I' and sw2.word = 'love' and sw3.word = 'you';

或者,如果您愿意:

where concat_ws(' ', sw1.word, sw2.word, sw3.word) = 'I love you'

从优化的角度来看,这更糟(使用 word 的索引对性能没有帮助),但很清楚查询在做什么。

此类搜索建议使用 full text index .唯一需要注意的是,您需要删除停用词列表并为所有单词编制索引,无论长度如何。 (“我”和“你”是停用词的典型例子。)

关于mysql - 如何在单词的SQL数据库中查询短语?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47541102/

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