1 回答
- 最新
- 投票最多
- 评论最多
0
【以下的回答经过翻译处理】 你好,
问题是你想如何接收标签数据?
是将它们放在不同的行或不同的列中吗?
如果可以将它们放在多行中,可以使用以下查询语句,使用SPLIT函数创建一个数组,然后使用该数组的结果在多行中使用unnest方法进行展开,详见这里:
with test_data as (select
'testcase1' as testcase, 'tag1,tag2,tag3' as tags
union all
select
'testcase2'as testcase , 'tag2,tag4' as tags
union all
select
'testcase3' as testcase, 'tag2' as tags
union all
select
'testcase4' as testcase,'' as tags )
select testcase, tag from test_data
cross join unnest(SPLIT(tags, ',')) as t(tag)
结果为:
如果你想要它在多列中,你应该使用SPLIT_PART函数,如下所示:
with test_data as (select
'testcase1' as testcase, 'tag1,tag2,tag3' as tags
union all
select
'testcase2'as testcase , 'tag2,tag4' as tags
union all
select
'testcase3' as testcase, 'tag2' as tags
union all
select
'testcase4' as testcase,'' as tags )
select testcase, SPLIT_PART(tags, ',',1) as tag1, SPLIT_PART(tags, ',',2) as tag2,
SPLIT_PART(tags, ',',3) as tag3, SPLIT_PART(tags, ',',4) as tag4
from test_data
结果为:
希望能帮到你
相关内容
- AWS 官方已更新 1 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 3 年前
- AWS 官方已更新 2 年前