2

I do have the following code.

    SQL> select * from student_gpa;

    SSN                    GPA
    --------------- ----------
   22222                    3
   11111                    4
   55555                    3
   33333                    4
   44444                    3

I do have this function to get the top two gpa score rows.

SQL> select * from (select ssn, gpa from student_gpa order by gpa desc) where rownum <= 2;

     SSN                    GPA
    --------------- ----------
    11111                    4
    33333                    4

My question is what function do I use to get the top n% of the GPA score. For example, Since I have two individuals with a GPA of 4, dense rank would return 11111 occupying row 1 and 22222 occupying row 2. I was actually looking for a function say that calculates 5% of the GPA score and the returned value would be both 11111 and 22222. The 5% function SHOULD NOT return 11111 only. Even if I had more entries that had gpa of 4, the 5% function would still return all rows that had gpa of 4.Thanks

4

4 に答える 4

0
 create table student_gpa(ssn number,gpa number);

 insert into student_gpa values(1111,4);
 insert into student_gpa values(2222,4);
 insert into student_gpa values(3333,3);
 insert into student_gpa values(4444,2);

 select ssn,gpa from(
   select ssn, gpa,dense_rank() over (order by gpa desc) rn from student_gpa
     )
   where rn =1;

    ssn   gpa
   --------------
   1111   4
   2222   4
于 2012-10-10T17:59:19.720 に答える