You are on page 1of 5

Name : Valaki Jay M.

Roll No : 21BCE312
Sub. Code & Name : 2CS402 – Database & Management System
Practical No. : 5
Date : 22/03/2023

Aim : Demonstration of Group by and having clause


1) Display the total expenditure of company on the salary of employees.
2) Find department wise total salary.
3) Find jobwise salary average.
4) Find the name of department taking maximum salary.
5) Find name of department taking minimum salary.
6) Find average salary of clerks.
7) Find average salary of managers and salesman.
8) Find employee with maximum annual income.
9) Find the employee with minimum monthly income.
10) List the emps in the ASC order of job ids of those joined after the
second half of 2014.
11) Find the number of employees earning more than average salary
of employees.
12) List the emps along with their Experience whose Daily Sal is more
than Rs.350.
13) List the emps in asc order of seniority.
14) List all the emps who joined before or after 2001.
15) List the emps who joined in the year 1990.
16) List the emps who joined in 2005.
17) Find the average of experience of all clerks (both ceil and floor
value).
18) List the emps who joined in January.
19) List the emps who have completed 10+ years today.
1)
select sum(salary) as total_expenditure from employees;

2)
select department_id, sum(salary) as deptwise_salary from employees group by
department_id;

3)
select job_id, avg(salary) as jobwise_avg_salary
from employees group by job_id;

4)
select department_id as department_id_having_maximum_salary, sum(salary) as dept_salary
from employees group by department_id
having dept_salary >= all(select sum(salary) from employees group by department_id);

5)
select department_id as department_id_having_minimum_salary, sum(salary) as dept_salary
from employees group by department_id
having dept_salary <= all(select sum(salary) from employees group by department_id);

6)
select job_id, avg(salary) as deptwise_avg_salary from employees group by job_id having
job_id='CLERK';
7)
select job_id, avg(salary) as deptwise_avg_salary from employees group by job_id having
job_id='FINANCIAL MANAGER' or job_id='SALES CLERK';

8)
select employee_id, first_name, last_name, job_id, 12*salary as max_annual_salary from
employees having max_annual_salary >= all(select 12*salary from employees);

9)
select employee_id, first_name, last_name, job_id, salary as min_monthly_salary from
employees having salary <= all(select salary from employees);

10)
select employee_id, first_name, last_name, job_id, salary from employees where
hire_date>'2014-06-30' order by job_id asc;

11)
select count(*) as num_of_employees_greater_than_avg_salary from employees where salary
> (select avg(salary) from employees);

12)
select employee_id, first_name, last_name, job_id,
salary from employees where salary>=31*350;
13)
select employee_id, first_name, last_name, hire_date, salary
from employees
order by hire_date asc;

14)
select employee_id, first_name, last_name, hire_date, salary
from employees
where hire_date < '2001-01-01' or hire_date > '2001-12-31';

15)
select employee_id, first_name, last_name, hire_date, salary
from employees
where hire_date > '1990-01-01' and hire_date < '1990-12-31';
16)
select employee_id, first_name, last_name, hire_date, salary, job_id
from employees
where hire_date >= '2005-01-01' and hire_date <= '2005-12-31';

17)
select avg(ceil(datediff(now(), hire_date)/365)) as avg_ceiling, avg(floor(datediff(now(),
hire_date)/365)) as avg_floor
from employees;

18)
select employee_id, first_name, last_name, job_id, salary, department_id, hire_date
from employees where month(hire_date)=1;

(It is empty because it don’t have the employee whose hire month is January).

19)
select employee_id, first_name, last_name, job_id, salary, department_id, hire_date
from employees where datediff(now(), hire_date) >= 3650;

You might also like