Oracle
 sql >> Base de données >  >> RDS >> Oracle

Top n pourcentage top n %

Vous pouvez essayer ceci :

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