2019년 3월 14일 목요일

Hive : Calculating Running Total

hive에서 누적합계 계산하기

create table

CREATE TABLE sample_rolling_sum(
    ins_date STRING
    , partition_no int
    , amount int
);

INSERT INTO sample_rolling_sum (ins_date, partition_no, amount)
VALUES
    (20190101, 0, 5),
    (20190102, 0, 5),
    (20190103, 0, 10),
    (20190104, 1, 10),
    (20190105, 2, 20),
    (20190106, 2, 5),
    (20190107, 2, 10),
    (20190108, 2, 5)
;

query


select
      ins_date, partition_no, amount
    , sum(amount) over(partition by partition_no order by ins_date) partition_r_sum 
    , sum(amount) over(order by ins_date) r_sum
from sample_rolling_sum

result



댓글 없음:

댓글 쓰기

추천 게시물

python: SVD(Singular Value Decomposition)로 간단한 추천시스템 만들기( feat. surprise )

svd_example In [15]: # !pip install surprise In [21]: from...