BSCS23034 Lab05
BSCS23034 Lab05
BSCS 23034
Database Lab05
Task 1:
select count(employee_id) from employees;
Task 2:
select count(employee_id) from employees
where month(hire_date) = 2 and
year(hire_date) = 2022;
Task 3:
select
count(employees.employee_id),departments.de
partment_name from employees inner join
departments on employees.department_id =
departments.department_id where
month(employees.hire_date) = 2 and
year(employees.hire_date) = 2022 group by
departments.department_id;
Task 4:
select employees.first_name, last_name from
employees where month(hire_date) = 2 and
year(hire_date) = 2022 and salary > 70000;
Task 5:
select
employees.first_name,employees.last_name
from employees inner join departments on
employees.department_id =
departments.department_id;
Task 6:
select
count(employees.employee_id),departments.de
partment_name from employees inner join
departments on employees.department_id =
departments.department_id where salary >
90000 group by employees.department_id;
Task 7:
select first_name , last_name from employees
where month(hire_date) = 2 and
year(hire_date) = 2022 and salary > 120000;
Task 8:
select
departments.department_name ,departments.b
udget, count(employees.employee_id) from
departments inner join employees on
departments.department_id =
employees.department_id group by
employees.department_id;
Task 9:
select departments.department_name ,
sum(employees.salary) from employees inner
join departments on employees.department_id
= departments.department_id group by
employees.department_id order by
sum(employees.salary) desc;
Task 10:
select first_name , last_name from employees
where instr(first_name, 'J') = 1 or
instr(last_name, 'J') = 1;
Task 11:
select first_name , last_name from employees
where instr(first_name, 'J') or instr(last_name,
'J');
Task 12:
select
employees.first_name ,employees.first_name,
departments.department_name from
employees inner join departments on
employees.department_id =
departments.department_id where
departments.location != 'London';
Task 13:
select departments.department_name as
dep_name, sum(employees.salary) as
total_sal , 100 *
sum(employees.salary)/departments.budget as
percent from employees inner join departments
on employees.department_id =
departments.department_id group by
employees.department_id;
Task 14:
select departments.department_name as
dep_name, employees.first_name,
employees.last_name ,
departments.department_name as dep_name
from employees inner join departments on
employees.department_id =
departments.department_id where
month(employees.hire_date) = 2 and
year(employees.hire_date) = 2022 and
instr(departments.location,'B') = 1;
Task 15:
select departments.department_name as
dep_name, sum(employees.salary) as
total_sal , sum(employees.salary) -
departments.budget as compare from
employees inner join departments on
employees.department_id =
departments.department_id group by
employees.department_id;
Task 16:
select first_name , last_name from employees
where salary > 100000 and (instr(first_name,
'J') or instr(last_name, 'J')) ;
Task 17:
select * from employees where year(curdate()-
hire_date) >1;
Task 18:
select count(employees.employee_id) as
emp_count,departments.department_name as
dpt_name , avg(employees.salary) as avg_sal
from employees inner join departments on
employees.department_id =
departments.department_id group by
departments.department_id;
Task 19:
select
departments.department_id,departments.depart
ment_name,
count(employees.department_id) AS
EMPLOYEES,
SUM(EMPLOYEES.SALARY) AS "SALARY
SUM",
ROUND((SUM(EMPLOYEES.SALARY)/count(e
mployees.department_id)),0) AS"AVERAGE
SAL",
CASE
WHEN
ROUND((SUM(EMPLOYEES.SALARY)/count(e
mployees.department_id)),0) <60000 THEN
'LOW'
WHEN
ROUND((SUM(EMPLOYEES.SALARY)/count(e
mployees.department_id)),0) BETWEEN 60000
AND 80000 THEN 'AVERAGE'
ELSE 'HIGH'
END AS SAL_CAT
from employees,departments
where
departments.department_id=employees.depart
ment_id group by departments.department_id;