首页 > 数据库 > 数据库开发技术 > 把列表中的ID转换成文字描述
有用户标签表如下 user_tag
有一张标签维表 tag表
请取出如下内容
select
tt.user_id,
concat_ws(',',collect_list(tag.tag_desc)) as tag_desc
from
(
select user_id,new_tag_id
from user_tag
lateral view outer explode(split(tag_id,',')) t as new_tag_id) tt
left join
tag
on tt.new_tag_id = tag.tag_id
group by tt.user_id

select user_id,new_tag_id
from user_tag
lateral view outer explode(split(tag_id,',')) t as new_tag_id
select
*
from
(
select user_id,new_tag_id
from user_tag
lateral view outer explode(split(tag_id,',')) t as new_tag_id) tt
left join
tag
on tt.new_tag_id = tag.tag_id
select
tt.user_id,
concat_ws(',',collect_list(tag.tag_desc)) as tag_desc
from
(
select user_id,new_tag_id
from user_tag
lateral view outer explode(split(tag_id,',')) t as new_tag_id) tt
left join
tag
on tt.new_tag_id = tag.tag_id
group by tt.user_id
create table user_tag
(
user_id bigint,
tag_id string
)
create table tag
(
tag_id bigint,
tag_desc string
)
insert into user_tag values
(111,'1,2,3'),
(222,'1,3,4'),
(333,null),
(444,'2');
insert into tag values
(1,'提前点送达'),
(2,'恶意刷单'),
(3,'非本人跑单'),
(4,'私自取消单');
原文作者:数据仓库技术;如有侵权,请联系管理员删除。