Sample Header Ad - 728x90

Sort by maximum value per partition

0 votes
1 answer
41 views
I have a table with data something like below:
| ID(pk) | name | count |
|--------|------|-------|
| id1    | xyz  |    98 |
| id2    | ptr  |     5 |
| id3    | xyz  |     2 |
| id4    | de   |     1 |
| id5    | ptr  |     1 |
I want to first have the row with max count then all the rows with same name sorted by count. After that next max count and all the counts with same name. Something like below:
| ID(pk) | name | count |
|--------|------|-------|
| id1    | xyz  |    98 |
| id3    | xyz  |     2 |
| id2    | ptr  |     5 |
| id5    | ptr  |     1 |
| id4    | de   |     1 |
Is something like this possible in Postgres?
Asked by gmtek (103 rep)
Jun 20, 2024, 11:44 AM
Last activity: Jun 21, 2024, 05:20 AM