滚动累加有两种方式:
1.第一种方式,抱歉我贴了一段自己写的SQL,大家只看蓝色标记的即可
DROP TABLE IF EXISTS tmp.tmp_group_bg_sales_budget_mth_2;
create table tmp.tmp_group_bg_sales_budget_mth_2 STORED AS ORC AS
select
bg_wid
,substr(sales_dt_wid,1,6) AS month_id
,substr(sales_dt_wid,1,4) AS year_id
,sum(coalesce(amt_bf_without_tax,0)) AS amt_bf_without_tax
,sum(coalesce(amt_af_without_tax,0)) AS amt_af_without_tax
,sum(sum(coalesce(amt_bf_without_tax,0))) OVER (PARTITION BY bg_wid,substr(sales_dt_wid,1,4) ORDER BY substr(sales_dt_wid,1,6)) AS amt_bf_without_tax_yth_ytd
,sum(sum(coalesce(amt_af_without_tax,0))) OVER (PARTITION BY bg_wid,substr(sales_dt_wid,1,4) ORDER BY substr(sales_dt_wid,1,6)) AS amt_af_without_tax_yth_ytd
,sum(coalesce(budget_amt_bf_without_tax,0)) AS budget_amt_bf_without_tax
,sum(coalesce(budget_amt_af_without_tax,0)) AS