There are two tables with the columns shown in brackets.
a. Employee(emp_id,emp_name,emp_salary,emp_dept_id)
b.Department(dept_id,dept_name)
Write a SQL to show the total salary for each department
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rahul BhattPosted Jul 21, 2012, 1:42 AM
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
Sudhakar ChaudharyPosted Jul 20, 2012, 2:29 PM
use cor
create table employee(emp_id int,emp_name varchar(50),emp_salary decimal(18,2),emp_dept_id int)
select * from employee
create table department(dept_id int,dept_name varchar(50))
SELECT employee.emp_dept_id, department.dept_name,sum(employee.emp_salary)as Salary
FROM department INNER JOIN employee ON department.dept_id = employee.emp_dept_id GROUP BY
employee.emp_dept_id,department.dept_name
Suthish NairPosted Jul 20, 2012, 2:03 PM