postgrelsql 的 wm_concat : string_agg


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM