string_agg,array_agg 这两个函数的功能大同小异,只不过合并数据的类型不同

 

array_agg(expression) 把表达式变成一个数组 一般配合 array_to_string() 函数使用

 

string_agg(expression, delimiter) 直接把一个表达式变成字符串

 

 

方法1:
select deptno, string_agg(ename, ',') from jinbo.employee group by deptno;

 deptno |  string_agg  
--------+--------------
     20 | JONES
     30 | ALLEN,MARTIN

方法2:
select deptno, array_to_string(array_agg(ename),',') from jinbo.employee group by deptno;
 deptno | array_to_string 
--------+-----------------
     20 | JONES
     30 | ALLEN,MARTIN

 

相关文章:

  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-02-05
  • 2022-12-23
猜你喜欢
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-09-07
  • 2021-09-14
  • 2021-06-06
相关资源
相似解决方案