Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Principais n por cento principais n%


Você pode tentar isso:
WITH     got_analytics     AS
(
     SELECT     ssn, gpa
     ,     ROW_NUMBER () OVER (ORDER BY  gpa  DESC)     AS r_num
     ,     COUNT (*)     OVER ()                                AS n_rows 
     FROM  student_gpa   
)
SELECT       ssn, gpa
FROM       got_analytics 
WHERE       r_num     <= ROUND (n_rows * 12/*insert here your n%*/ / 100)
ORDER BY  gpa     DESC