我有一个包含 5 列的表,即:
before_1, before_2, before_3, rule, name
其中 before_1、before_2 和 before_3 是文档中名称/单词之前的三个单词。
我想找到的是:
Which are the two words that occur together before a name. I don't want just the top words, but all the words sorted by the number of occurrences.
我尝试了以下几个查询,但这对我不起作用。
select count(before_2),count(before_3),name from data_with_before_words group by name;
两列的计数相同,这不是我所期望的。
示例数据:
前 5 行:
before_1,before_2,before_2,rule,name
a,league,of,Persona,Amell
the,assasin,of,Persona,Amell
the,league,of,Persona,Amell
a,assasin,of,Persona,Amell
a,league,of,Persona,Amell
预期输出:
league,of,3,Amell
assasin,of,2,Amell
如有任何帮助,我们将不胜感激。
最佳答案
要获得预期的输出,您可以使用以下查询
select before_2,before_3,name,count(*)
from data_with_before_words
group by before_2,before_3,name
order by count(*) desc
关于MySQL:按多列分组未给出准确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47827261/