SQL> select num,count(*),RATIO_TO_REPORT(count(*)) over() Percent from test1 GROUP BY num;       NUM   COUNT(*)    PERCENT
---------- ---------- ----------
         1          1        0.1
         2          3        0.3
         3          2        0.2
         4          2        0.2
         5          1        0.1
         8          1        0.16 rows selected

解决方案 »

  1.   

    你的结果:
    select age,count(*) as counter,RATIO_TO_REPORT(count(*)) over() as Percent from student GROUP BY age order by counter desc
      

  2.   

    SELECT A.AGE, A.COU, TO_CHAR(ROUND(A.COU / A.COU_ALL, 4) * 100) 
          || '%' AS percent
    FROM (SELECT AGE, COUNT(*) AS COU, MAX
                      ((SELECT COUNT(*)
                      FROM student)) AS COU_ALL
            FROM student
            GROUP BY AGE) A
      

  3.   

    RATIO_TO_REPORT(count(Id)) over()在mysql中不能使用