I need to group by a certain column and to make the first occurrence into another group.
select * from table;
So something like that:
select min(id) id, currency, sum(amount) from table group by currency, case when min(id)=id then 'first-occurrence' else 'rest' end;
Of course the
case doesn't make much sense. The goal is make it also fast, and if possible not to read the table again as the table is huge.