将数组列转换为 Presto 中的 table 个 K,V 对
Convert column of arrays to table of K,V pairs in Presto
我有一个带有一列字符串数组的 presto 我想将数组中每个元素的 table 转换为映射到其出现次数的
A、B、C、D、E、F都是字符串
set
---------
[A,B,C,D]
[A,C,E,F]
string|count
-------------
A 2
B 1
C 2
D 1
E 1
F 1
好吧,你可以使用 unnest()
和聚合:
select char, count(*)
from t cross join
unnest(t.set) as u(char)
group by char
我有一个带有一列字符串数组的 presto 我想将数组中每个元素的 table 转换为映射到其出现次数的
A、B、C、D、E、F都是字符串
set
---------
[A,B,C,D]
[A,C,E,F]
string|count
-------------
A 2
B 1
C 2
D 1
E 1
F 1
好吧,你可以使用 unnest()
和聚合:
select char, count(*)
from t cross join
unnest(t.set) as u(char)
group by char