I have a query:
select id, type_id, sum(values)
group by id, type_id
order by 2, 3 desc;
The problem is that I only want the top 20 id's ( top 20 based on the sum(values) column ) for each type_id, instead of ALL ids for each type_id.
There is an ever growing amount of type_ids (i.e. 500+), so setting up a bunch of union-ed queries isn't a desirable option.
Is there a way to do this in oracle(or postgres). Any help if greatly appreciated.