Oracle 中的 SUM(COUNT(*))

SUM(COUNT(*)) in Oracle

我在 Oracle 的 HR 模式中使用受欢迎的员工 table。示例数据:https://imgur.com/3Xw6go7 我正在尝试找出与 table.

具有相同薪水的人数以及百分比

但是,当我尝试以下查询时出现错误:

SELECT SALARY, count(*),((count(*)/sum(count(*))))*100 FROM EMPLOYEES
group by salary;

ORA-00937: not a single-group group function
00937. 00000 -  "not a single-group group function"
*Cause:    
*Action:

但是,当我尝试下面的查询时,我得到了想要的结果。

SELECT SALARY, count(*),(count(*)/(select sum(count(*)) from employees group by salary))*100 FROM EMPLOYEES
group by salary;

有人可以告诉我如何使用第一个查询本身实现我的目标吗?我知道 count() returns 很多行,而 sum (count()) returns 只有 1 行。

您缺少 OVER() 子句:

SELECT SALARY, count(*),
       count(*) * 100 / sum(count(*)) OVER ()
FROM EMPLOYEES
GROUP BY salary;