Create array in SELECT

前端 未结 3 2086
别跟我提以往
别跟我提以往 2021-02-09 07:27

I\'m using PostgreSQL 9.1 and I have this data structure:

A     B
-------
1     a
1     a
1     b
1     c
1     c
1     c
1     d
2     e
2     e
3条回答
  •  自闭症患者
    2021-02-09 08:14

    Maybe I'm missing something, but this should do it:

    SELECT a, 
           count(*) as cnt,
           array_agg(b) as all_values
    FROM your_table
    GROUP BY a
    

提交回复
热议问题