impala transpose column to row

流过昼夜 提交于 2019-12-12 17:40:11

问题


How to transpose column data to row data in impala I have tried some solution that not work in impala but working in hive.

Table name : test
Data:
day         name     jobdone
2017-03-25  x_user   5
2017-03-25  y_user   10
2017-03-31  x_user   20
2017-03-31  y_user   1

I want the data should be like that in impala no in hive

Required Output Data
 Day           x_user     y_user
 2017-03-05    5          10
 2001-03-31    20         1

I am able to do in Hive using the Map and collect_list. How can i do in Impala.


回答1:


Using case + min() or max() aggregation:

select day,
       max(case when name='x_user' then jobdone end) x_user,
       max(case when name='y_user' then jobdone end) y_user
  from test
  group by day;

Use sum() instead of max() if there are many records per user, day and you need to sum them.



来源:https://stackoverflow.com/questions/50098917/impala-transpose-column-to-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!