赞
踩
目录
输出结果如下所示:
1
2
3
4
5
...
100
方法一:起始值(start)+步长(diff)=结束值(end)
select split(space(5), ' ')
- +----------------------+
- | _c0 |
- +----------------------+
- | ["","","","","",""] |
- +----------------------+
select posexplode(split(space(5), ' '))
- +------+------+
- | pos | val |
- +------+------+
- | 0 | |
- | 1 | |
- | 2 | |
- | 3 | |
- | 4 | |
- | 5 | |
- +------+------+
- select
- id_start+pos as id
- from(
- select
- 1 as id_start,
- 100 as id_end
- ) m lateral view posexplode(split(space(id_end-id_start), ' ')) t as pos, val
方法2:利用row_number() over()生成id序列
- select
- row_number() over() as id
- from
- ( select explode(split(space(99), ' '))) t ;
本问题解决主要用到:posexplode()或row_number()函数,row_number() over()可生成整表的id。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。