为以下问题编写配置单元查询以打印id值如果id为1则打印id 1次,如果id值为2则打印id 2次,依此类推
Input TableId---1234Output-------Id--1223334444
Input Table
Id
---
1
2
3
4
Output
-------
--
9fkzdhlc1#
使用 space(id-1) 要获取长度为id-1的空格字符串,请拆分字符串并使用侧向视图+ explode 生成行。演示:
space(id-1)
explode
with your_table as (select stack (4,1,2,3,4) as id)select t.id from your_table t lateral view outer explode(split(space(id-1),' ')) e
with your_table as (
select stack (4,
1,
2,
3,
4) as id
)
select t.id
from your_table t
lateral view outer explode(split(space(id-1),' ')) e
结果:
t.id1223334444
t.id
更多说明: split(space(id-1),' ') -这将生成id-1空间数组 explode() -是一个表生成函数,从数组生成表 lateral view outer 工作方式类似于主表与explode生成的表的左联接。对于每一行,它与explode()的每一行连接,并以这种方式为每一行生成重复项。
split(space(id-1),' ')
explode()
lateral view outer
1条答案
按热度按时间9fkzdhlc1#
使用
space(id-1)
要获取长度为id-1的空格字符串,请拆分字符串并使用侧向视图+explode
生成行。演示:
结果:
更多说明:
split(space(id-1),' ')
-这将生成id-1空间数组explode()
-是一个表生成函数,从数组生成表lateral view outer
工作方式类似于主表与explode生成的表的左联接。对于每一行,它与explode()的每一行连接,并以这种方式为每一行生成重复项。