怎么用DM的函数实现类似array_agg的效果,listagg都只能返回字符串,我需要返回数组,并且选中数组中的某一项,比如:
select array_agg(name)[1] from table_name group by age;
可以试试以下方式实现
create table city(country varchar(20),city varchar(20));
insert into city values(‘中国’,‘台北’);
insert into city values(‘中国’,‘香港’);
insert into city values(‘中国’,‘上海’);
insert into city values(‘日本’,‘东京’);
insert into city values(‘日本’,‘大阪’);
insert into city values(‘美国’,‘纽约’);
select country,wm_concat(city),REGEXP_SUBSTR(wm_concat(city), ‘[^,]+’, 1, 1),
REGEXP_SUBSTR(wm_concat(city), ‘[^,]+’, 1, 2),REGEXP_SUBSTR(wm_concat(city), ‘[^,]+’, 1, 3)
from city group by country;
select wm_concat(name)||‘[1]’ from table_arr group by age; 这样?