溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Hive學(xué)生選課情況統(tǒng)計(jì)

發(fā)布時(shí)間:2020-06-29 17:29:37 來源:網(wǎng)絡(luò) 閱讀:405 作者:zjy1002261870 欄目:大數(shù)據(jù)

編寫Hive的HQL語(yǔ)句來實(shí)現(xiàn)以下結(jié)果:表中的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的學(xué)生選修了課程a,b,c,d,e,f中其中幾門
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

create table t_stu_course
(
id int,
course string
) row format delimited fields terminated by ",";
load data local inpath "/root/t_stu_course.txt" into table t_stu_course;

select tmp.id
,max(tmp.a) as a
,max(tmp.b) as b
,max(tmp.c) as c
,max(tmp.d) as d
,max(tmp.e) as e
,max(tmp.f) as f
from (
select id
,case when course="a" then 1 else 0 end as a
,case when course="b" then 1 else 0 end as b
,case when course="c" then 1 else 0 end as c
,case when course="d" then 1 else 0 end as d
,case when course="e" then 1 else 0 end as e
,case when course="f" then 1 else 0 end as f
from t_stu_course
) tmp
group by tmp.id;

select collect_set(course) as courses from t_stu_course;

set hive.strict.checks.cartesian.product=false;

select t1.id as id,t1.course as id_courses,t2.course courses
from
( select id as id,collect_set(course) as course from t_stu_course group by id ) t1
join
(select collect_set(course) as course from t_stu_course) t2;

啟用嚴(yán)格模式:hive.mapred.mode = strict // Deprecated
hive.strict.checks.large.query = true
該設(shè)置會(huì)禁用:1. 不指定分頁(yè)的orderby
       2. 對(duì)分區(qū)表不指定分區(qū)進(jìn)行查詢
       3. 和數(shù)據(jù)量無關(guān),只是一個(gè)查詢模式
hive.strict.checks.type.safety = true
嚴(yán)格類型安全,該屬性不允許以下操作:1. bigint和string之間的比較
                  2. bigint和double之間的比較
hive.strict.checks.cartesian.product = true
該屬性不允許笛卡爾積操作

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI