Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 搜索最多的单词MYSQL_Php_Mysql - Fatal编程技术网

Php 搜索最多的单词MYSQL

Php 搜索最多的单词MYSQL,php,mysql,Php,Mysql,我有一个MySQL表,记录每个访问者的搜索词。有时是一个单词,有时是多个单词。在我的后端,我想列出搜索最多的单词desc limit x 当然,我可以用PHP实现,但我想知道用MySQL是否也可以 search_string -------------- Hotel in Berlin Paris New York Grand Hotel Principe Royal Myconian Resort Thalasso Spa Spa Resort 我知道像纽约这样的城市可以分为纽约和纽约,但忽

我有一个MySQL表,记录每个访问者的搜索词。有时是一个单词,有时是多个单词。在我的后端,我想列出搜索最多的单词desc limit x

当然,我可以用PHP实现,但我想知道用MySQL是否也可以

search_string
--------------
Hotel in Berlin
Paris
New York
Grand Hotel Principe
Royal Myconian Resort Thalasso Spa
Spa Resort
我知道像纽约这样的城市可以分为纽约和纽约,但忽略这一点


谢谢你的帮助

可以在单个查询中执行此操作,但必须假定最大字数

select word, count(*) as cnt
from (select substring_index(substring_index(search_string, ' ', n.n), ' ', -1) as word
      from searches s cross join
           (select 1 as n union all select 2 union all select 3 union all select 4 union all select 5
           ) n
      where length(replace(search_string, ' ', ' x')) - length(search_string) <= n
     ) w
group by word
order by cnt desc;

对substring_index的嵌套调用将返回列表中的第n个单词。where子句验证在lesat列表中是否有许多单词。

可以在单个查询中执行此操作,但必须假定最大单词数

select word, count(*) as cnt
from (select substring_index(substring_index(search_string, ' ', n.n), ' ', -1) as word
      from searches s cross join
           (select 1 as n union all select 2 union all select 3 union all select 4 union all select 5
           ) n
      where length(replace(search_string, ' ', ' x')) - length(search_string) <= n
     ) w
group by word
order by cnt desc;

对substring_index的嵌套调用将返回列表中的第n个单词。where子句验证在lesat列表中是否有许多单词。

可以在单个查询中执行此操作,但必须假定最大单词数

select word, count(*) as cnt
from (select substring_index(substring_index(search_string, ' ', n.n), ' ', -1) as word
      from searches s cross join
           (select 1 as n union all select 2 union all select 3 union all select 4 union all select 5
           ) n
      where length(replace(search_string, ' ', ' x')) - length(search_string) <= n
     ) w
group by word
order by cnt desc;

对substring_index的嵌套调用将返回列表中的第n个单词。where子句验证在lesat列表中是否有许多单词。

可以在单个查询中执行此操作,但必须假定最大单词数

select word, count(*) as cnt
from (select substring_index(substring_index(search_string, ' ', n.n), ' ', -1) as word
      from searches s cross join
           (select 1 as n union all select 2 union all select 3 union all select 4 union all select 5
           ) n
      where length(replace(search_string, ' ', ' x')) - length(search_string) <= n
     ) w
group by word
order by cnt desc;

对substring_index的嵌套调用将返回列表中的第n个单词。where子句验证列表中有多少单词。

使用全文搜索:1。打开浏览器,2。导航到google.com 3。通过计数或其他方式搜索mysql组。根据你的发现写代码Hanks PravinS。埃利亚斯和约书亚还有一个问题。评论会给你带来声誉吗?或者你为什么要花时间去写一些无用的、冒犯性的Elias答案?使用全文搜索:1。打开浏览器,2。导航到google.com 3。通过计数或其他方式搜索mysql组。根据你的发现写代码Hanks PravinS。埃利亚斯和约书亚还有一个问题。评论会给你带来声誉吗?或者你为什么要花时间去写一些无用的、冒犯性的Elias答案?使用全文搜索:1。打开浏览器,2。导航到google.com 3。通过计数或其他方式搜索mysql组。根据你的发现写代码Hanks PravinS。埃利亚斯和约书亚还有一个问题。评论会给你带来声誉吗?或者你为什么要花时间去写一些无用的、冒犯性的Elias答案?使用全文搜索:1。打开浏览器,2。导航到google.com 3。通过计数或其他方式搜索mysql组。根据你的发现写代码Hanks PravinS。埃利亚斯和约书亚还有一个问题。评论会给你带来声誉吗?或者你为什么要花时间去写毫无用处的、冒犯性的Elias答案?字数是动态的,但我会继续研究你的解决方案。谢谢,字数是动态的,但我会继续研究你的解决方案。谢谢,字数是动态的,但我会继续研究你的解决方案。谢谢,字数是动态的,但我会继续研究你的解决方案。谢谢