例如需要复制tmp_1表n次,每复制一次,gday+1,直到gday=200,
借助 lateral view posexplode,首先用space复制多个空格字符串,复制次数=200-gday
然后split将字符串分割成数组,此时该数组大小为200-gday
然后lateral view posexplode创建虚拟表,虚拟表大小也为200-gday文章来源:https://www.toymoban.com/news/detail-525643.html
用gday+虚拟表的索引,即可得到递增的gday,且gday最大值为200文章来源地址https://www.toymoban.com/news/detail-525643.html
with tmp_1 as (
select 'a' as rearer,
150 as gday,
2.3 as rate
union all
select 'b' as rearer,
160 as gday,
5 as rate
)
select id_start+pos, rate as id
from( select gday as id_start, 200 as id_end, rate from tmp_1) m
lateral view posexplode(split(space(id_end-id_start), '')) t as pos, val
到了这里,关于HIVE 复制行n次直到某一列等于200的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!