Presto - 计算所有行中字符串的出现次数
Presto - Count Occurrences of Strings in All Rows
我是 Presto 的新手,正在尝试针对以下 table colors
编写查询。我试过使用 flatten
和 histogram
但没有成功。有人可以帮我弄清楚如何实现这一目标吗?谢谢!
row words
0 yellow blue red
1 red
2 yellow red
words 现在是 varchar
的列表。
期望的输出:
word count
yellow 2
red 3
blue 1
这是我目前的情况:
WITH
dataset AS (
SELECT ARRAY
[
ARRAY['yellow','blue','red'],
ARRAY['red'],
ARRAY['yellow','red']
] AS words
)
SELECT words
FROM dataset
一种方法是将其转换为数组,然后是 table 并计数:
select w.word, count(*)
from t cross join
unnest(split(t.words, ' ')) as w(word)
group by w.word;
我是 Presto 的新手,正在尝试针对以下 table colors
编写查询。我试过使用 flatten
和 histogram
但没有成功。有人可以帮我弄清楚如何实现这一目标吗?谢谢!
row words
0 yellow blue red
1 red
2 yellow red
words 现在是 varchar
的列表。
期望的输出:
word count
yellow 2
red 3
blue 1
这是我目前的情况:
WITH
dataset AS (
SELECT ARRAY
[
ARRAY['yellow','blue','red'],
ARRAY['red'],
ARRAY['yellow','red']
] AS words
)
SELECT words
FROM dataset
一种方法是将其转换为数组,然后是 table 并计数:
select w.word, count(*)
from t cross join
unnest(split(t.words, ' ')) as w(word)
group by w.word;