Top n percent top n%

后端 未结 4 618
暖寄归人
暖寄归人 2020-12-12 02:38

I do have the following code.

    SQL> select * from student_gpa;

    SSN                    GPA
    --------------- ----------
   22222                          


        
4条回答
  •  时光说笑
    2020-12-12 02:46

    You can try this:

    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           
    

提交回复
热议问题