• Status: Solved
• Priority: Medium
• Security: Public
• Views: 380

need query to find each group salary percentage from the totalsal

i have a dept table which contains

deptno deptname empid salary

1       sales             10    1000

2       libray             11    2000

3        IT                 12    5000

4       sales            14    6000

5       libray           15    5000

6        IT               16    9000

7        IT                17    19000

8      libray             18    7000

pls provide me the query to find each group salary percentage  from the totalsal
0
mu_ravi1
2 Solutions

Commented:
What formula you wat to use to calculate salary percentage ?

to get total sal

select deptname , sum(salary) from tabelname
group by deptname
0

Author Commented:
hi

i need totalgroupsal/totalsal
ravi
0

Commented:
select deptname , sum(salary)/(select sum(salary) from tablename) from tabelname
group by deptname
0

Commented:

declare @total int

select @total = sum(salary0 from table1

select deptname, sum(salary)/@total * 100.0 as Percentage
from table1
0

Commented:
Option 1 :

Select DeptName,convert(numeric(10,2),(sum(Sal)*100.0)/Tot) from Table_1,
(Select sum(Sal)as 'Tot' from table_1 )A
group by DeptName,Tot

Other use Variable

Declare @Tot int
set @Tot=(Select sum(Sal)from Table_1)
Select DeptName,(sum(Sal)*100.0)/@Tot from table_1
Group By DeptName
0

Author Commented:
good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.