Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have a table like:
SQL
empId empSalary empDept
1   45000   IT
2   40000   IT
3   50000   SALES
4   60000   SALES
5   75000   IT
6   80000   IT
7   25000   OPS
8   30000   OPS
9   55000   MARKETING
10  60000   MARKETING


I have to write a query as:

SQL
select empId where empSalary  > avg(empSalary) for each  empDept


Kindly help.
Posted

1 solution

hi,
try this

SQL
select empId from tbl t1 where empSalary  >
 (select AVG(empSalary) from tbl t2 m where t1.empDept =t2.empDept )
 
Share this answer
 
Comments
Mahatma Aladdin 6-Dec-14 2:49am    
thanx mate. just a bit modification and i got what i needed.

select empDept,count(empId) from tbl_Emp t1 where empSalary >
(select AVG(empSalary) from tbl_Emp t2) group by empDept
King Fisher 6-Dec-14 2:50am    
well :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900