一、資料準備
有如下資料:用戶名,月份,訪問次數
A,2015-01,5
A,2015-01,15
B,2015-01,5
A,2015-01,8
B,2015-01,25
A,2015-01,5
A,2015-02,4
A,2015-02,6
B,2015-02,10
B,2015-02,5
A,2015-03,16
A,2015-03,22
B,2015-03,23
B,2015-03,10
B,2015-03,1
二、需求分析
1、創建表
create table requirement( name string, month string, num int ) row format delimited fields terminated by ',';
2、上傳資料
load data local inpath '/usr/mydir/data/requirement.txt' into table requirement;
3、驗證資料是否正確
select * from requirement;
4、查詢資料
SELECT name, month, month_sum, MAX(month_sum) over(partition by name order by month) max, SUM(month_sum) over(partition by name order by month) sum from( SELECT name,month,SUM(num) as month_sum from requirement group by name,month ) t1;
三、結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/206096.html
標籤:大數據
上一篇:我的splash頁面怎么少東西
