user11624254
user11624254

Reputation:

postgresql - getting an ordered array from table

for a table like this

id|col
1 |a
2 |b
3 |a

I would like to get an array of just col elements ordered by how often they appear in the table. how can this be done?

Upvotes: 0

Views: 34

Answers (1)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48207

SELECT ARRAY(SELECT col
             FROM yourTable
             GROUP BY col
             ORDER BY COUNT(*) );

Upvotes: 2

Related Questions