0

I have an Oracle table with ID, SUBJECT, and PAYLOAD (CLOB). I'd like to get a listing of the TOP 10 records who have the biggest PAYLOAD (LENGTH(PAYLOAD)) grouped by subject. So if I have 10 DISTINCT SUBJECT's in the table, the query should return 100 rows (top 10 per subject).

Domenic D.
  • 5,276
  • 4
  • 30
  • 41

1 Answers1

2

Use row_number():

select t.*
from (select t.*, row_number() over (partition by subject order by length(payload) desc) as seqnum
      from table t
     ) t
where seqnum <= 10;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786