postgres order by max values code example
Example: sort by highest number postgres
postgres=# select deptno,max(sal) from emp group by deptno order by max(sal);
deptno | max
--------+---------
30 | 2850.00
20 | 3000.00
10 | 5000.00
(3 rows)