Sum Employees salary according to depatments.
In sql server two tables is given, employee table and department table, and employee table contains approx 50 employees and his/her salary on each departments vise, and departments table contains department_id and department name, i want to to exit out sum of salary of every department separately according to each departments .
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


Rahul Bhatt165 reputationPosted Jul 21, 2012, 12:49 AM EDT
Need to use JOIN with Group BY
select TableB.dept_name, SUM(TableA.emp_salary) from Employee as TableA
Inner join Department as TableB
on TableA.emp_dept_id = TableB.dept_id
Group by TableB.dept_name