Home » SQL & PL/SQL » SQL & PL/SQL » to find out % of total
to find out % of total [message #188996] Tue, 22 August 2006 13:15 Go to next message
samyugtha
Messages: 14
Registered: November 2005
Junior Member
Hi,

I have to write one query to find the % of Total of the salary.

SQL> select * from employee;

EMPNAME EMPNUM SALARY DATEOFBIRTH
---------- ------ ------ -----------
aruna 1 10000 9/23/1977
varuna 2 10000 9/23/1977
kesh 3 10000 9/23/1977
raj 4 10000 9/23/1977
aparana 5 10000 9/23/1977
animesh 6 10000 9/23/1977

I need to calculate each and every members salary % from the total salary. For eg for aruna the salary % will be
10000/(60000)* 100 = 16.67%. Like that I want to calculate for each and every employee in a single query.

If any one have idea pls help me to resolve. Otherwise I've to use the same table more than once to find the total salary.

Thanks in advance

Sam
Re: to find out % of total [message #189002 is a reply to message #188996] Tue, 22 August 2006 13:45 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
sql>select ename, sal, 
  2         round(ratio_to_report(sal) over (partition by null) * 100, 1) sal_percent
  3    from emp;

ENAME            SAL SAL_PERCENT
---------- --------- -----------
SMITH            800         2.8
ALLEN           1600         5.5
WARD            1250         4.3
JONES           2975        10.2
MARTIN          1250         4.3
BLAKE           2850         9.8
CLARK           2450         8.4
SCOTT           3000        10.3
KING            5000        17.2
TURNER          1500         5.2
ADAMS           1100         3.8
JAMES            950         3.3
FORD            3000        10.3
MILLER          1300         4.5

14 rows selected.
Re: to find out % of total [message #189004 is a reply to message #189002] Tue, 22 August 2006 14:13 Go to previous message
samyugtha
Messages: 14
Registered: November 2005
Junior Member
Thanks a lot Todd Barry

[Updated on: Tue, 22 August 2006 15:40] by Moderator

Report message to a moderator

Previous Topic: Year Format
Next Topic: Tuning PLSQL PROCEDURE
Goto Forum:
  


Current Time: Sat Dec 10 18:51:28 CST 2016

Total time taken to generate the page: 0.04402 seconds