zoukankan      html  css  js  c++  java
  • Hive 行列转换

    一、列转行 (对某列拆分,形成新列)

    使用函数:lateral view explode(split(column, ',')) num

    eg: 如表:t_row_to_column_tmp 数据如下,对tag列进行拆分

    SQL代码:

    select id,tag,tag_new

      from t_row_to_column_tmp

    lateral view explode(split(tag, ',')) num as tag_new

    where id=212022894;

    二、行转列 (根据主键,对某列进行合并)

    使用函数:concat_ws(',',collect_set(column))  

    说明:collect_list 不去重,collect_set 去重。 column 的数据类型要求是 string

    eg:如表:t_column_to_row ,根据id,对tag_new 进行合并

    SQL代码1:

    select id,

             concat_ws(',',collect_set(tag_new)) as tag_col

     from t_column_to_row

    group by id;

    SQL代码2:

    select id,

             concat_ws(',',collect_list(tag_new)) as tag_col

     from t_column_to_row

    group by id;

    -------> by kimbo_zhang
  • 相关阅读:
    python while 格式化 运算符 编码
    python 变量 if
    1、cad安装
    10、云存储—文件上传
    9、云函数
    8、云数据库
    8、小程序云开发
    7、页面交互js
    6、页面样式WXSS
    5、页面结构WXML
  • 原文地址:https://www.cnblogs.com/kimbo/p/6208973.html
Copyright © 2011-2022 走看看