gpt4 book ai didi

php - SQL 查询查找所有两个单词组合

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

使用 PHP 和 MySQL,我需要从包含超过一百万行的表中查找按计数排序的所有“两个单词”组合。

搜索需要查找每个两个单词组合的出现次数,例如“hardware store”、“to the”、“second opportunity”、“for those”、“senior Citizen”等。

要搜索的文本示例:

id | content
1 | The senior citizens went to the hardware store from the community center.

2 | The hardware store is offering a second chance drawing for those senior citizens who did not win.

3 | Many senior citizens go to the town's community center to play bingo.

结果示例:

senior citizens - 3
to the - 2
hardware store - 2
community center - 2
second chance - 1
The senior - 1
center to - 1
the town's - 1
etc ...and so on.

结果需要包含所有“两个单词”组合。 “前辈”、“去了”、“硬件”、“市民去了”等,并统计找到了多少次。

我猜这可能是一个带有子查询的多查询解决方案,但我的查询构建专业知识很少。我尝试了一些基本查询,但我认为解决方案将比我的技能更复杂一些。

Similar question with different data source .

最佳答案

尝试 Union All 加入:

SELECT count(*) FROM your_table WHERE content LIKE '%senior citizens%'
UNION ALL
SELECT count(*) FROM your_table WHERE content LIKE '%to the%'
UNION ALL
SELECT count(*) FROM your_table WHERE content LIKE '%hardware store%'

关于php - SQL 查询查找所有两个单词组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196134/

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