table: gulivideo_orc
字段:videoid, uploader, age, category, length,
views, rate, ratings, comments, relatedid
table: gulivideo_user_orc
字段:uploader, videos, friends
select videoid, views
from gulivideo_orc
order
by views desc
limit
10;
select videoid, category_name
from gulivideo_orc
lateral view explode(category) temp_category as category_name; t1
select category_name,
count(*
) category_count
from
(select videoid, category_name
from gulivideo_orc
lateral view explode(category) temp_category as category_name
)t1group
by category_name
order
by category_count desc
limit
10;
select videoid, views, category
from gulivideo_orc
order
by views desc
limit
20; t1
2)對 t1 表中的category_name進行炸裂
select category_name
from t1
literal view explode(category) temp_category as category_name; t2
3)對 t2 表進行分組求和
select category_name,
count(*
) category_count
from t2
group
by category_name
order
by category_count desc
; t3
綜合**:
select category_name,
count(*
) category_count
from
(select category_name
from
(select videoid, views, category
from gulivideo_orc
order
by views desc
limit
20)t1
literal view explode(category) temp_category as category_name
)t2group
by category_name
order
by category_count desc
; t3
select relatedid, views
from gulivideo_orc
order
by views desc
limit
50; t1
2) 對 t1 表中的relatedid進行炸裂,並去重。
select related_id
from t1
lateral view explode(relatedid) temp_related as related_id
group
by related_id; t2
select category
from t2
join gulivideo_orc orc
on t2.related_id = orc.videoid; t3
4)對 t3 表中的category進行炸裂
select explode(category_name) category_name
from t3; t4
5)分組(類別)求和
select category_name,
count(*
) category_count
from t4
group
by category_name
order
by category_count desc
; t5
綜合**:
select category_name,
count(*
) category_count
from
(select explode(category_name) category_name
from
(select category
from
(select related_id
from
(select relatedid, views
from gulivideo_orc
order
by views desc
limit
50)t1
lateral view explode(relatedid) temp_related as related_id
group
by related_id
)t2join gulivideo_orc orc
on t2.related_id = orc.videoid
)t3)t4
group
by category_name
order
by category_count desc
;
select uploader, videos
from gulivideo_user_orc
order
by videos desc
limit
10; t1
select video.videoid, video.views
from t1
join gulivideo_orc
on t1.uploader = video.uploader
order
by video.views desc
limit
20; t2
select
categoryid,
videoid,
views,
rank(
)over
(partition
by categoryid order
by views desc
) rk
from gulivideo_category; t1
select categoryid, videoid, views
from t1
where rk <=
10;
Hive基礎 案例
h ive shell 檢視所有資料庫 show databases 建立資料庫 create database database name 切換資料庫 use database name 檢視所有表 show tables 模糊查詢表 show tables like name 檢視所有的hive...
HIVE專案實戰
字段 備註詳細描述 video id 11位字串 uploader agecategory length views 次數 rate 滿分5分 ratings 流量conments related ids 2 使用者表 表6 14 使用者表 字段備註 字段型別 uploader 上傳者使用者名稱 s...
Hive 15 實戰案例3 級聯求和
有如下訪客訪問次數統計表 t access times 訪客月份 訪問次數 a2015 01 025a 2015 01 0315b 2015 01 015a 2015 01 048b 2015 01 0525a 2015 01 065a 2015 02 024a 2015 02 066b 2015 ...