Martin Patel Roll No:-55 DIV-1
ASSIGNMENT:2
1. Select total salary spent for each department. (sum(salary) group by dept_id).
QUERY: select dept_id,sum(salary) as total_salary from employee group by dept_id;
OUTPUT:
2. Find number of employees(count) working for each department (count(emp_id) group
by dept_id ).
QUERY: select dept_id,count(emp_id) as employee_count from employee group by
dept_id;
OUTPUT:
3. Find total salary spent for each department > 20000. (having caluse)
QUERY: select dept_id,sum(salary) as total_salary from employee group by dept_id
having sum(salary)>20000;
OUTPUT:
4. Find total salary spent for each department 20000. Display records in ascending order
of salary sum.
QUERY: select dept_id, sum(salary) as total_salary from employee group by dept_id
having sum(salary) <30000;
OUTPUT:
Page 1|3
Martin Patel Roll No:-55 DIV-1
5. Select total salary spent for each department. Display records in descending order of
salary sum.
QUERY: select dept_id,sum(salary) as total_salary from employee group by dept_id
order by total_salary desc;
OUTPUT:
6. Find total salary spent for each department > 20000. Display records in ascending order
of salary sum.
QUERY: select dept_id,sum(salary) as total_salary from employee group by dept_id
having sum(salary) > 20000 order by total_salary asc;
OUTPUT:
7. Write switch case for salary column with following conditions:
Conditions Message
Salary <10000 Employee is intern
Salary>=10000 and salary < 20000 Grade 3 employee
salary >= 20000 and salary < 30000 Grade 2 employee
Salary >= 30000 Grade 1 employee
QUERY: select emp_id,salary,case
...> when salary < 10000 then 'employee in litern'
Page 2|3
Martin Patel Roll No:-55 DIV-1
...> when salary >= 10000 and salary < 20000 then 'grade 3 employee'
...> when salary >= 20000 and salary < 30000 then 'grade 2 employee'
...> when salary >= 30000 then 'grade 1 employee'
...> else 'unknown category'
...> end as salary_grade from employee;
OUTPUT:
Page 3|3