hive sum函式的頂級應用(配合開窗函式OVER)
阿新 • • 發佈:2019-02-08
首先參考http://jingyan.baidu.com/article/8cdccae969e758315413cd1e.html
(可能需要使用hdfs使用者,執行hive命令)create table tmp.hive_sum(id string COMMENT '會員ID',bank_name string COMMENT '銀行名稱',create_time string COMMENT '交易時間',amount double COMMENT '交易金額') COMMENT 'hive_sum頂級應用' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';
load data inpath '/test/input/hive_sum.txt' overwrite into table tmp.hive_sum;
select id,bank_name,create_time,amount,sum(amount) over(partition by id) amount_all from hive_sum order by id,bank_name,create_time;
select id,bank_name,create_time,amount,sum(amount) over(partition by id) amount_all from hive_sum order by amount_all;
select id,bank_name,create_time,amount,sum(amount) over(partition by id,bank_name order by create_time asc ) amount_all from tmp.hive_sum order by id,bank_name,create_time asc;
select id,create_time, amount,sum(amount) over(partition by id order by create_time asc rows between 2 preceding and 2 following ) amount_all from tmp.hive_sum order by id, create_time asc;
select id,bank_name,sum(amount) amount_all from tmp.hive_sum group by id,bank_name with rollup order by id, bank_name desc ;