蜂巢学生选课情况统计

  

编写蜂巢的HQL语句来实现以下结果:表中1的表示选修,表中的0表示未选修
id a b c d e f
1 1 1 1 0 1 0
2 1 0 1 1 0 1
3 1 1 1 0 1 0
表示有id为1、2、3的学生选修了课程a, b, c, d, e, f中其中几门课程
id
,
1, b
1, c
1, e
2,
2, c
2 d
2, f
3
3 b
3, c
3 e

  

create table t_stu_course
(
id int,
课程字符串
)行格式分隔字段终止由“、“
数据加载本地inpath“/根/t_stu_course.txt"表t_stu_course;

  

选择tmp.id
,
max (tmp.a),马克斯(tmp.b) b
,马克斯(tmp.c) c
,马克斯(tmp.d) d
,马克斯(tmp.e) e
,马克斯(tmp.f) f
(
选择id
,当课程=癮"那么其他1 0作为
结束,当课程=癰"那么其他1 0 b
结束,当课程=癱"那么其他1 0 c
结束,当课程=癲"那么其他1 0 d
结束,当课程=癳"那么其他1 0 e
结束,当课程=癴"那么其他1 0结束从t_stu_course f

) tmp
group by tmp.id;

  

选择collect_set t_stu_course(课程)课程;

  

设置hive.strict.checks.cartesian.product=false;

  

选择t1。id作为id、t1。课程作为id_courses, t2。课程课程

(选择id作为id, collect_set(课程)课程从t_stu_course组id) t1

(选择collect_set(课程)课程从t_stu_course) t2;

  

启用严格模式:hive.mapred。严格模式=//弃用
hive.strict.checks.large。查询=true
该设置会禁用:1。不指定分页的orderby
2。对分区表不指定分区进行查询
3。和数据量无关,只是一个查询模式
hive.strict.checks.type。安全=true
严格类型安全,该属性不允许以下操作:1。长整型数字和字符串之间的比较
2。长整型数字和双之间的比较
hive.strict.checks.cartesian。产品=true
该属性不允许笛卡尔积操作

蜂巢学生选课情况统计