1、演示多列转为单行

数据文件及内容: student.txt

xiaoming|english|92.0

xiaoming|chinese|98.0

xiaoming|math|89.5

huahua|chinese|80.0

huahua|math|89.5

创建表studnet:

create table student(name string,subject string,score decimal(4,1))

row format delimited

fields terminated by ‘|’;

导入数据:

load data local inpath ‘/home/hadoop/hivetestdata/student.txt’ into table student;

列转为行演示:

hive (hive)> select name,concat_ws(‘,’,collect_set(subject)) from student group by name;

huahua chinese,math

xiaoming english,chinese,math

hive (hive)> select name,concat_ws(‘,’,collect_set(concat(subject,’=’,score))) from student group by name;

huahua chinese=80,math=89.5

xiaoming english=92,chinese=98,math=89.5

2、演示单行转为多列

数据文件及内容:student2.txt

huahua|chinese=80,math=89.5

xiaoming|english=92,chinese=98,math=89.5

创建表:

create table student2(name string,subject_score_list string)

row format delimited

fields terminated by ‘|’;

导入数据:

load data local inpath ‘/home/hadoop/hivetestdata/student2.txt’ into table student2;

行转为列演示:

hive (hive)> select * from student2;

student2.name student2.subject_score_list

huahua chinese=80,math=89.5

xiaoming english=92,chinese=98,math=89.5

hive (hive)> select name, subject_list from student2 stu2 lateral view explode(split(stu2.subject_score_list,’,’))stu_subj as subject_list; —-别名一定不要忘记

huahua chinese=80

huahua math=89.5

xiaoming english=92

xiaoming chinese=98

xiaoming math=89.5

hive中实现行转列_##[函数]Hive中行列转换(行转列)相关推荐

  1. linux 列转行函数,Linux 文本行列转换

    使用awk进行行列转换 假设有一个文件 test ,包含的数据遵循以下格式: 同一行数据,单词之间为1个空格" " 每一行都有同样多的数据,个数相同 处理命令: awk '{for ...

  2. mysql 行转列_详解MySQL行列转换4个实现方案及反向行转列实验测试

    概述 今天主要做一个实验,先理解下mysql行列转换,后面在做一下反向的行列转换. 需求 二维关系转换为三维关系. 1.环境准备 create database test;use test;creat ...

  3. python怎么选取不连续的列_用pandas中的DataFrame时选取行或列的方法

    如下所示: import numpy as np import pandas as pd from pandas import Sereis, DataFrame ser = Series(np.ar ...

  4. python中numpy数组的合并_基于Python中numpy数组的合并实例讲解

    基于Python中numpy数组的合并实例讲解 Python中numpy数组的合并有很多方法,如 - np.append() - np.concatenate() - np.stack() - np. ...

  5. python中gmtime的hour错误_python中gmtime的hour错误_在Python中操作日期和时间之gmtime()方法的使用...

    python中datetime怎么用广告总是在最精彩的时候出现,你总是在小编爱的最深的时候离开. ''''' 日期相关的操作 ''' from datetime import datetime fro ...

  6. sql 如何设置行级锁_如何使用SQL Server 2016行级安全性过滤和阻止数据访问

    sql 如何设置行级锁 SQL Server 2016 came with many new features and enhancements for existing ones, that con ...

  7. cmd中如何运行python文件_在cmd中运行.py文件: python的操作步骤

    在cmd中运行.py文件: python的操作步骤 1 打开cmd, 不改变运行的目录: 输入python 空格  调试好的python文件路径 或者python 空格  将python文件拖入cmd ...

  8. mysql pivot函数怎么用_浅析SQL语句行列转换的两种方法 case...when与pivot函数的应用...

    /*创建数据库*/ CREATE DATABASE tmp go USE tmp go /*创建数据库测试表*/ CREATE TABLE [Scores] ( [ID] INT IDENTITY(1 ...

  9. python中args1是什么意思_理解Python中的*,*args

    1.*在函数调用中的作用 首先定义一个函数,并调用 deffun(a, b, c):printa, b, c fun(1,2,3) 则该函数的输出为 1 2 3 传递3个参数调用该函数,则该函数会打印 ...

  10. python 写入csv文件固定列_将元组列表写入csv文件保持列一致

    我用beauthulsoup抓取一个网站,页面的一半有常规数据,X#个字段每个字段有一个值,下半部分有Y#个字段,每个字段都有可变数量的值(很多时候只有一个值,其他的是任意数量的值).在 困扰我的是如 ...

最新文章

  1. 10gocm-gt;session3-gt;数据备份与恢复
  2. 网页设计布局选择:固定,流行和弹性布局 (2010-12-14 13:07:35)
  3. 服务器tail正常,cat正常,vim打开中文乱码
  4. 两天学会css基础(一)
  5. 3.4 内置函数(1)
  6. 我们正在经历一个应用疲惫时代?
  7. php验证码图片看不清更换代码,php如何实现验证码看不清换一张的效果
  8. springcloud用于开发什么项目_为什么说新产品开发有三种形式的项目计划?
  9. qq怎样发起临时会话(不加好友)
  10. 树莓派B+安装简单版魔镜MagicMirror
  11. 开发板识别不了SD/TF卡
  12. AcWing 1097 池塘计数
  13. cisco 路由器 ADSL拨号上网配置
  14. 华为云迁移工具推荐最佳实践:物理服务器迁移到华为云
  15. 《特征值与特征向量》定义、意义及例子
  16. 网易邮箱无法正常登陆的解决技巧
  17. 中等职业学校计算机类教学用书,中等职业学校计算机技术专业教学用书:二维动画制作(Flash CS3)...
  18. MacOS技巧|Mac如何自定义触控栏Touch Bar?显示Touch Bar教程
  19. pands 画图 调整大小_图片处理小技巧(调整大小、批量命名),超级实用
  20. 树莓派IMX708摄像头模块

热门文章

  1. BIOS中未启用虚拟化支持系列~~例如:因此无法安装Hyper-V
  2. 模版,自定义按钮背景xml
  3. CentOS7 MongoDB安裝
  4. 开启Github之旅
  5. 【用户】create_user_with_sshkey.sh
  6. windows 任务管理中各个内存项的含义
  7. html中div弹出显示
  8. 使用 artitalk + LeanCloud 配置给个人博客搭建说说
  9. PHP 变量 与 运算符
  10. voronoi图代码_在Unity中实时计算Voronoi图