最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - Substring a variable and add preceding year's value in Hive - Stack Overflow

programmeradmin2浏览0评论

I'm trying to reduce a string to two values and attach the previous year's value in Hive.

I'm looking to substring the column as follows:

create table substring_income_dataset
select year, substring(income_total, 1, 2), benefit_type, sum(household_income),
    count(*)
from income_dataset
group by year, benefit_type, substring(income_total, 1, 2)

I'm also looking to use the lag function to include the previous year's value based on a primary key:

create table previous_year_income as
select*,
    lag(benefit_type,1,0) over (partition by primary_key) as previous_benefit_type,
    lag(income_total,1,0) over (partition by primary_key) as previous_income_type
from income_dataset;

Can somebody please suggest how I can combine the two?

发布评论

评论列表(0)

  1. 暂无评论