postgresql – 当串联两列时,如何在字符串agg中添加顺序

postgresql – 当串联两列时,如何在字符串agg中添加顺序,第1张

概述SELECT string_agg( distinct a || '-' || b , ',' ORDER BY a,b) FROM table; 上面的sql给出了错误 ERROR: in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list 对于 the documentation: If @H_403_7@SELECT string_agg( distinct a || '-' || b,',' ORDER BY a,b) FROM table;

上面的sql给出了错误

ERROR: in an aggregate with disTINCT,ORDER BY Expressions must appear in argument List

解决方法 对于 the documentation:

If disTINCT is specifIEd in addition to an order_by_clause,then all the ORDER BY Expressions must match regular arguments of the aggregate; that is,you cannot sort on an Expression that is not included in the disTINCT List.

所以试试吧

@H_403_7@select string_agg(distinct a || '-' || b,' order by a || '-' || b)from a_table;

或在派生表中使用distinct:

@H_403_7@select string_agg(a || '-' || b,' order by a,b)from ( select distinct a,b from a_table ) s; 总结

以上是内存溢出为你收集整理的postgresql – 当串联两列时,如何在字符串agg中添加顺序全部内容,希望文章能够帮你解决postgresql – 当串联两列时,如何在字符串agg中添加顺序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1159049.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存