tags:

views:

93

answers:

1

I came up with following query which is not so challenging to resolve but still I think there might be better approach for this. Any suggessions? Thanks in advance.

I have got following table

tb_Salary

EmpID DeptID Salary
---------------------
1  1  20000
2  1  20000
3  2  30000
4  2  800
5  2  200

I want to increase the salary of employees by Rs. 1000 only when the average salary in the department is more than 10000.

Is this possible using single update query?

I did this in following way. But seems that it is not that smart solution.

UPDATE t1
SET t1.salary=t1.salary+1000
from salary t1
WHERE 10000 < (select AVG(t2.Salary) from Salary t2 WHERE t2.DeptID=t1.DeptID)

+1  A: 

Your query is the way to go.

neolace
Hi neolace,it's giving error for aggregate function... Also my query had some errors which I have corrected now.
Anil