当列 "A" 相同时,我想 select 列 "B" 作为列表

I want to select a column "B" as a list when it's column "A" is the same

当 "A" 列相同时,我想将 select 列 "B" 作为列表。假设我有:

A                | B 
-----------------------------------
10000            | 5000         
10000            | 5000         
10001            | 9090        
10002            | 9090         
10000            | 9090 

因此,我想要:

A                | B 
-----------------------------------
10000            | '5000,5000,9090'               
10001            | '9090'        
10002            | '9090'         

我该怎么办?谢谢大家!

你可以试试这个

select A, array_to_string( array_agg("B"), ' , ') from tablename GROUP BY A order by A

更多参考请访问this