多条记录某字段的连接

引用


如题,比如表(table_a)内容:
  id                           name
  1                             zs
  2                             ls
  3                             as

能够通过一条sql语句,输出 'zs,ls,as'

11g里面用listagg,10g里面用wm_concat
select listagg(name,',') within (order by id) from table;

select wm_concat(name) from table;

select to_char(wm_concat(name)) names from table_a ;


其他的例子:code可以对应多个name
select code, to_char(wm_concat(name) ) up_key
  from match_code
WHERE code = '409001'
group by code;

猜你喜欢

转载自airendos.iteye.com/blog/1564813
今日推荐