提取位置
题目 提取1的位置
create table position_1(
a varchar(7) comment '含1的字符串'
) comment '1的位置';
insert into position_1
values ('1011'),('0101');
解决 字符串拆成数组
with tmp as(-- 1.字符串添加分隔符
select
a,
concat_ws('-',substring(a,1,1),substring(a,2,1),substring(a,3,1),substring(a,4,1)) a1
from position_1
)
select -- 3.posexplode 位置
a,a1, -- Hive不能直接访问非group by字段
concat_ws('-',collect_list