SQL:如何获取一列语句行中所有字符串的总和

SQL:如何获取一列语句行中所有字符串的总和,sql,Sql,是否有一个sql查询能够将所有句子分割成字符串,对它们进行计数并返回前3个最常见的字符串 例如:- 在MySQL中,您可以使用以下内容解析单词: | string | sum | |-------------|-----| | cool | 5 | | love | 3 | | lamb | 2 | 请注意,此版本仅获取前三个单词。您需要展开n,以获得列中的最大字数 然后,您可以聚合为: select substring_index

是否有一个sql查询能够将所有句子分割成字符串,对它们进行计数并返回前3个最常见的字符串

例如:-


在MySQL中,您可以使用以下内容解析单词:

|   string   | sum |
|-------------|-----|
|    cool     |  5  |
|    love     |  3  |
|    lamb     |  2  |
请注意,此版本仅获取前三个单词。您需要展开
n
,以获得列中的最大字数

然后,您可以聚合为:

select substring_index(substring_index(col, ' ', n.n), ' ', -1) as word
from (select 1 as n union all select 2 as n union all select 3 as n
     ) n join
     t
     on col like concat(repeat('% ', n.n - 1), '%');

PostgreSQL具有全文搜索功能。MySQL没有现成的插件,但可能有某种插件…@Pavitran。没有一个简单的机制。
select substring_index(substring_index(col, ' ', n.n), ' ', -1) as word
from (select 1 as n union all select 2 as n union all select 3 as n
     ) n join
     t
     on col like concat(repeat('% ', n.n - 1), '%');
select substring_index(substring_index(t.col, ' ', n.n), ' ', -1) as word,
       count(*)
from (select 1 as n union all select 2 as n union all select 3 as n
     ) n join
     t
     on col like concat(repeat('% ', n.n - 1), '%')
group by word