Write query to find total salary for each department and department total salary greater than 10000
Output:
Solution:
create table deptsal2 (emp_name varchar(20),dept_id integer,salary integer)
This is a SQL code to create a table named "deptsal2" with three columns:
1. "emp_name" with a data type of varchar(20) to store employee names
2. "dept_id" with a data type of integer to store the department ID
3. "salary" with a data type of integer to store the salary of the employees.
insert into deptsal2 values("A",1,10000),("B",1,2000),("C",2,5000),("D",3,7000),("E",3,1000)
Insert value in table "deptsal2".
select dept_id,sum(salary)as total_salary from deptsal2 group by dept_id having total_salary > 10000;
This is a SQL query to retrieve the total salary for each department (grouped by the "dept_id" column) where the total salary is greater than 10,000. The query performs the following operations:
1. Selects the "dept_id" and the sum of the "salary" column calculated as "total_salary".
2. Groups the data by the "dept_id" column.
3. Filters the results to include only the departments where the "total_salary" is greater than 10,000, using the "having" clause.
The result of the query will be a table with two columns: "dept_id" and "total_salary". The table will include only the departments where the total salary is greater than 10,000.
Comments
Post a Comment