oracle分组后合并其中一个字段 (2)

时间:2021-11-14 13:32:02

1、

SELECT wmsys.wm_concat(t.org) orgs, t.area_name
FROM (SELECT concat(concat(b.abbreviation, '-'), b.org_name) org,
a.area_name area_name
FROM t_organization  b
left join t_area_store a
on a.store_code = b.unit_id
WHERE b.close_date is null
and b.abbreviation is not null
ORDER BY a.area_name) t
group by t.area_name

该语句获取的结果为:orgs 字段类型为clob类型,若果前段需要展示时得再次处理

oracle分组后合并其中一个字段 (2)

 

2、

SELECT LISTAGG(to_char(t.org), ',') within group(ORDER BY t.area_name) as orgs,
t.area_nameFROM (SELECT concat(concat(b.abbreviation, '-'), b.org_name) org,
a.area_name area_name
FROM t_organization b
left join t_area_store a
on a.store_code = b.unit_id
WHERE b.close_date is null
and b.abbreviation is not null
ORDER BY a.area_name) t
group by t.area_name

结果为:orgs字段为字符串类型,前端页面展示无需再次处理

oracle分组后合并其中一个字段 (2)