admin管理员组文章数量:1420985
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?
本文标签: sqlSubstring a variable and add preceding year39s value in HiveStack Overflow
版权声明:本文标题:sql - Substring a variable and add preceding year's value in Hive - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744595508a2614751.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论