【问题标题】:I work with postgresql and i have a database like this [duplicate]我使用postgresql,我有一个这样的数据库[重复]
【发布时间】:2020-08-26 18:23:53
【问题描述】:
Col1 Col2
_________
A   |  1
A   |  2
A   |  3
B   |  4
B   |  5
B   |  6

我需要得到这样的东西

col1 list
________
A   | 1,2,3
B   | 4,5,6

我还是初学者给我最简单的选择

【问题讨论】:

标签: sql postgresql string-aggregation


【解决方案1】:

使用array_agg尝试以下操作

select
    col1,
    array_agg(col2)
from yourTable
group by
    col1

string_agg

select
    col1,
    string_agg(col2, ', ')
from yourTable
group by
    col1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2021-11-23
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    相关资源
    最近更新 更多