我有以下查询:
SELECT Sub_Type, count(Sub_Type)
FROM SOME_TABLE
GROUP BY Sub_Type
Sub_Type字段类型是字符串
的嵌入列表我得到的结果是:
Blotter_Sub_Type | count
["A"] | 2
["B"] | 3
["C"] | 3
["A","B"] | 1
["B","C"] | 1
但是当我真正想要获得每个值的出现次数时,我的预期结果是:
Blotter_Sub_Type | count
"A" | 3
"B" | 5
"C" | 4
意味着它将单独计算每个值的出现次数
答案 0 :(得分:1)
您必须使用UNWIND和子查询:
SELECT Sub_Type, count(Sub_Type) FROM (
SELECT Sub_Type FROM SOME_TABLE UNWIND Sub_Type
) GROUP BY Sub_Type