select * from( select t.code, sum(t.totalsum) from smdocdisccard t, smdocuments a where t.doctype=a.doctype and t.id=a.id and to_date(a.createdat,'DD.MM.YY') > to_date('31.12.2005', 'DD.MM.YY') group by t.code order by sum(t.totalsum) desc) where rownum<11