Top n percent top n%

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

I do have the following code.

    SQL> select * from student_gpa;

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


        
4条回答
  •  青春惊慌失措
    2020-12-12 02:58

    First 30 percent with 2 selects:

    select ssn,gpa from(
    select ssn, gpa,rank() over (order by gpa asc) as rn, count(*) over() as cnt
    from student_gpa
    )
    where rn < 0.3*cnt ;
    

    Solution with 4 selects and rownum (very ugly):

    select ssn,gpa from(
    select ssn, gpa
    from student_gpa
    )
    where rownum < 0.3*(select count(*) from (select ssn, gpa from student_gpa));
    

提交回复
热议问题