Thursday, May 2, 2013

How to find total salary of each employee IN SQL??


I have a department table and i find out to total salary of each employee by department Id.

DeptId       Name      Salary
1            AA        2000 
1            AA       3000 
2            BB       1000
3            cc        1000
3            cc        4000
 
 sql query


SELECT E.DeptId,ISNULL(SUM(ES.Salary),0) AS Amt FROM Employee E
LEFT OUTER JOIN Employee ES ON E.DeptId=ES.DeptId
GROUP BY E.DeptId


 Output

DeptId             Salary
1                   5000 
2                   1000
3                   5000

No comments :

Post a Comment