当前位置:   article > 正文

聚合函数 postgre的string_agg、array_agg 和Oracle的WM_CONCAT、LISTAGG 和 Mysql的GROUP_CONCAT_oracle array_agg和pg的array_agg

oracle array_agg和pg的array_agg

 

一、PostgreSQL

函数说明

  1. array_agg(expression)
  2. 把表达式变成一个数组 一般配合 array_to_string() 函数使用
  3. string_agg(expression, delimiter)
  4. 直接把一个表达式变成字符串

使用案例 

select student, string_agg(score, ',' order by questionord) from table_score group by student;
  1. select array_agg(distinct class) from table_student;
  2. select array_agg(distinct class order by class desc) from table_student;

使用注意

array_agg 直接使用字符,需要加入类型转换。否则会报错。

array_agg('-'::VARCHAR order by ord)

 

参考:

https://blog.csdn.net/u011944141/article/details/78902678

 

 

二、Oracle

使用案例

select to_char(WMSYS.WM_CONCAT(score)) from table_score group by student;

 

select LISTAGG(SCORE, ',') WITHIN GROUP (ORDER BY QUESTIONORD) from table_score;

 

三、MySQL

使用案例

select CONVERT (GROUP_CONCAT(SCORE order by score desc separator ';') USING utf8) from table_score,

参考:

https://www.cnblogs.com/bigbigbigo/p/10952895.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/85728
推荐阅读
相关标签
  

闽ICP备14008679号