基于列的配置单元sql包数组
我在下面列出了多个栏目:基于列的配置单元sql包数组,sql,hive,Sql,Hive,我在下面列出了多个栏目: state sport size color name florida football 1 red Max nevada football 1 red Max ohio football 1
state sport size color name
florida football 1 red Max
nevada football 1 red Max
ohio football 1 red Max
texas football 1 red Max
florida hockey 1 red Max
nevada hockey 1 red Max
ohio hockey 1 red Max
texas hockey 1 red Max
florida tennis 2 green Max
nevada tennis 2 green Max
ohio tennis 2 green Max
texas tennis 2 green Max
是否有一种方法可以基于一列(在本例中为名称)将这些内容组合到数组中,如下面所需的输出。Mac结果将有一条记录,而不是重复记录,这些记录将包含在一个数组中
state sport
[florida, nevada, ohio,texas] [football, hockey, tennis]
size color
[1,2] [red, green]
您可以使用
collect\u set
select name,collect_set(state),collect_set(sport),collect_set(size),collect_set(color)
from tbl
group by name
您可以使用
collect\u set
select name,collect_set(state),collect_set(sport),collect_set(size),collect_set(color)
from tbl
group by name
您需要使用collect_set。希望这有帮助。谢谢
query:
select collect_set(state),
collect_set(sport),
collect_set(size),
collect_set(color)
from myTable
where name = 'Max';
您需要使用collect_set。希望这有帮助。谢谢
query:
select collect_set(state),
collect_set(sport),
collect_set(size),
collect_set(color)
from myTable
where name = 'Max';