我们有时想看人员表每个人收入在整个收入中占多大比例,我们这里以EMPLOYEES为例,为了好看,我们选择20部门来举例:
SQL> select last_name ,salary from employees where department_id=20;
LAST_NAME SALARY
------------------------- ----------
Hartstein 13000
Fay 6000
查看每个人的薪水在总的薪水中占多大比例,我们一般使用子查询来完成:
SQL> select last_name,salary,round(
2 100* (
3 salary/(select sum(salary) from employees where department_id=20)
4 )
5 ) as pct_sal
6 from employees where department_id=20;
LAST_NAME SALARY PCT_SAL
------------------------- ---------- ----------
Hartstein 13000 68
Fay 6000 32
|