SQL行合并值

select t2.tag_name 名称, t1.*
  from (select tag_relations as id,
               ltrim(sys_connect_by_path(tag_name, '-'), '-') as 详情
          from (select tag_relations,
                       tag_name,
                       row_number() over(partition by tag_relations order by tag_name) rn,
                       count(*) over(partition by tag_relations) cnt
                  from test_temp
                 where tag_relations != '0') a
         where level = cnt
         start with rn = 1
        connect by prior tag_relations = tag_relations
               and prior rn = rn - 1) t1,
       test_temp t2
 where t1.id = t2.tag_id;

猜你喜欢

转载自zxw961346704.iteye.com/blog/2121580