我有一个包含2列ID和URL的表,每个ID都有几个URL。我想每个ID只提取5个最大URL。我如何在Oracle SQL中执行此操作?
答案 0 :(得分:7)
试试这个,
SELECT ID, URL
FROM
(
SELECT ID, URL,
ROW_NUMBER() OVER (PARTITION BY ID ORDER BY URL DESC) RN
FROM tableName
) a
WHERE RN <= 5