简体   繁体   中英

Use select query to add values to a hive column

I am having a hive table AAA having 5 columns, say A,B,C,D,E. I want to add a column F to AAA, such that all rows of F should contain maximum value of E. Example :

TABLE AAA

A|B|C|D|E 
__________
1|2|3|4|5
2|3|4|5|6
3|4|5|6|7

Add column F to AAA. Final table should have something like this.

A|B|C|D|E|F 
___________
1|2|3|4|5|7 
2|3|4|5|6|7 
3|4|5|6|7|7 

You can use window functions:

select t.*, max(e) over() as f
from aaa t

I wouldn't recommend storing this derived information, because it is hard to maintain (whenever a e value changes on any row, then you might need to recompute the while f column).

An alternative would be to create a view:

create view v_aaa as
select t.*, max(e) over() as f
from aaa t

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM