我有一个带有ID,SUBJECT和PAYLOAD(CLOB)的Oracle表。我想获得按主题分组的最大PAYLOAD(LENGTH(PAYLOAD))的十大记录列表。因此,如果表中有10个DISTINCT SUBJECT,则查询应返回100行(每个主题前10位)。
答案 0 :(得分:2)
使用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;