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

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
thanks inadvance
0
mu_ravi1
Asked:
mu_ravi1
2 Solutions
 
Pratima PharandeCommented:
What formula you wat to use to calculate salary percentage ?

to get total sal

select deptname , sum(salary) from tabelname
group by deptname
0
 
mu_ravi1Author Commented:
hi

i need totalgroupsal/totalsal
ravi
0
 
Pratima PharandeCommented:
select deptname , sum(salary)/(select sum(salary) from tablename) from tabelname
group by deptname
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Ephraim WangoyaCommented:

declare @total int

select @total = sum(salary0 from table1

select deptname, sum(salary)/@total * 100.0 as Percentage
from table1
0
 
samijsrCommented:
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
 
mu_ravi1Author 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.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now