This statement will give each name with its maximum amount.
select name, max(amount) as max_amt
from jobs
group by name
order by max_amt desc;
Raj 50
Nish 25
Rahul 22
Krish 8
Sorting on max_amt desc
gives us the groups in the right order. Now all we need to do is join that to the "jobs" table, and sort the result by the two numerical columns.
I used a CTE to simplify things a bit.
with max_amounts as (
select name, max(amount) as max_amt
from jobs
group by name
)
select t1.*, t2.max_amt from jobs t1
inner join max_amounts t2
on t2.name = t1.name
order by max_amt desc, amount desc;
In standard SQL, I think you can just remove max_amt from the outer SELECT clause, and still use order by max_amt desc
.