加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL – string_agg,元素数量有限

发布时间:2020-12-13 18:09:43 所属栏目:百科 来源:网络整理
导读:是否可以限制以下string_agg函数中的元素数量? string_agg(distinct(tag),',') 我不知道你可以在string_agg()函数中限制它.您可以通过其他方式限制它: select postid,string_agg(distinct(tag),')from table tgroup by postid 然后你可以这样做: select p
是否可以限制以下string_agg函数中的元素数量?
string_agg(distinct(tag),',')
我不知道你可以在string_agg()函数中限制它.您可以通过其他方式限制它:
select postid,string_agg(distinct(tag),')
from table t
group by postid

然后你可以这样做:

select postid,string_agg(distinct (case when seqnum <= 10 then tag end),')
from (select t.*,dense_rank() over (partition by postid order by tag) as seqnum
      from table t
     ) t
group by postid

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读