博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hive实战之学生选课
阅读量:4635 次
发布时间:2019-06-09

本文共 668 字,大约阅读时间需要 2 分钟。

 


数据(基表course):

id course 1,a 1,b 1,c 1,e 2,a 2,c 2,d 2,f 3,a 3,b 3,c 3,e

需求:编写Hive的HQL语句来实现以下结果:表中的1表示选修,表中的0表示未选修。

id    a    b    c    d    e    f1     1    1    1    0    1    02     1    0    1    1    0    13     1    1    1    0    1    0

实现需求的步骤:

  使用case...when...将不同的课程名称转换成不同的列。

create  table student as selectid as id ,case course when a then 1 else 0 end as a,case course when b then 1 else 0  end as b,case course when c then 1 else 0  end as c,case course when d then 1 else 0  end as d,case course when e then 1 else 0  end as e,case course when f then  1 else 0  end as ffrom  group by id,course;

 

转载于:https://www.cnblogs.com/songweideboke/p/9851033.html

你可能感兴趣的文章
网络表示学习总结
查看>>
完成评论功能
查看>>
far和near
查看>>
Python爬虫实战四之抓取淘宝MM照片
查看>>
2015 Multi-University Training Contest 1
查看>>
C#判断一个字符串是否是数字或者含有某个数字
查看>>
SVN使用指南
查看>>
【转载】掌 握 3 C ‧ 迎 接 亮 丽 职 涯
查看>>
爬取网站附件
查看>>
java基础图形界面和IO系统
查看>>
javascript学习笔记
查看>>
hdu 3996
查看>>
python第三十九课——面向对象(二)之初始化属性
查看>>
python学习笔记之函数装饰器
查看>>
FEM计算2D瞬态热传导方程
查看>>
四年时光,匆匆而过
查看>>
【php】【psr】psr1 基础编码规范
查看>>
JAVA 文本 TXT 操作工具类
查看>>
js实现多行文本溢出省略
查看>>
Android中Tomcat的简单配置和使用
查看>>