Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Obtenha os principais 'n' registros por report_id


Que tal
SELECT *
FROM (SELECT *,
         ROW_NUMBER() OVER(PARTITION BY report_id ORDER BY (SELECT 0)) AS RN
         FROM top_keywords
         WHERE ym BETWEEN '2010-05' AND '2010-05') TK
WHERE RN <= 10