School of Computer Science Engineering (SCOPE)
Name: Tirthankar Gupta
Registration
No. : 21BCE0324
Date:
20.05.2023
Assessment 2
Exercise: III
Operators and Functions
Aim: To understand different operators and types of function in SQL Execute
the following queries based on the schema specified in exercise 1
1. Find the employee names having salary greater than Rs.25000.
2. Find the employee names whose salary lies in the range between 30000 and 70000.
3. Find the employees who have no supervisor.
4. Display the bdate of all employee s in the format ‘DDthMonthYYYY’.
5. Display the employee names whose bdate is on or before 1978.
6. Display the employee names having ‘salt lake’ in their address.
7. Display the department name that starts with ’M’.
8. Display the department names’ that ends with ‘E’.
9. Display the names of all the employees having supervisor with any of the following
SSN 554433221, 333445555.
10. Display all the department names in upper case and lower case.
11. Display the first four characters and last four of the department names using ltrim
and rtrim.
12. Display the substring of the Address (starting from 5th position to 11 th position) of all
employees.
13. Display the Mgrstartdate on adding three months to it.
14. Display the age of all the employees rounded to two digits.
15. Find the last day and next day of the month in which each manager has joined.
Code Snippet
select first_name from employee55 where salary>25000;
select first_name from employee55 where salary between 30000 and 70000;
select first_name from employee55 where supervisor_ssn is null;
select to_char(birthday,'ddth fmmonth yyyy') from employee55;
select first_name from employee55 where birthday<'01-JAN-78';
select first_name from employee55 where address like '%Salt Lake%';
select department_name from dept where department_name like '%M';
select department_name from dept where department_name like '%E';
select department_name from dept where department_name like '%e';
select first_name, supervisor_ssn from employee55 where supervisor_ssn in (554433221, 333445555);
select upper(department_name)from dept;
select lower(department_name)from dept;
Select substr(address,5,11) from employee55;
Select add_months(manage_start_date,3) as new_manage_start_date from dept;
Select first_name, round((months_between(sysdate,birthday)/12),2) from employee55;
Select last_day(manage_start_date) from dept;
Output
Exercise: IV
Group Functions
1. How many different departments are there in the ‘employee’ table
2. For each department display the minimum and maximum employee salaries
3. Print the average annual salary.
4. Count the number of employees over 30 age.
5. Print the Department name and average salary of each department.
6. Display the department name which contains more than 30 employees.
7. Calculate the average salary of employees by department and age
8. Count separately the number of employees in the finance and research department.
9. List out the employees based on their seniority.
10. List out the employees who works in ‘manufacture’ department group by first name
Code Snippet
desc employee55;
select *from employee55;
UPDATE Dept
SET Department_name='Headquarter'
WHERE Department_number=3;
UPDATE Dept
SET Department_name='Finance'
WHERE Department_number=4;
UPDATE Dept
SET Department_name='Research'
WHERE Department_number=5;
ALTER TABLE employee55 ADD Department_Name varchar2(15);
UPDATE employee55
SET Department_name='Manufacture'
WHERE Department_number=1;
UPDATE employee55
SET Department_name='Administration'
WHERE Department_number=2;
UPDATE employee55
SET Department_name='Headquarter'
WHERE Department_number=3;
UPDATE employee55
SET Department_name='Finance'
WHERE Department_number=4;
UPDATE employee55
SET Department_name='Research'
WHERE Department_number=5;
//1. How many different departments are there in the ‘employee’ table?
select count(distinct department_number) from Employee55;
//2. For each department display the minimum and maximum employee salaries
select min(salary),max(salary) from employee55;
//3. Print the average annual salary.
select avg(salary*12) from employee55;
//4. Count the number of employees over 30 age.
select count(ssn) from employee55 where (abs(extract(year from sysdate)-(extract(year from
birthday)))>30);
//5. Print the Department name and average salary of each department.
select department_name, avg(salary) from employee55 group by department_name;
//6. Display the department name which contains more than 30 employees.
SELECT d.DEPARTMENT_NAME
FROM employee55 e
JOIN dept d ON e.DEPARTMENT_NUMBER = d.DEPARTMENT_NUMBER
GROUP BY d.DEPARTMENT_NAME
HAVING COUNT(*) > 30;
//7. Calculate the average salary of employees by department and age
select distinct department_number,months_between(sysdate,birthday)/12,avg(salary) from
employee55 group by department_number,months_between(sysdate,birthday)/12;
//8. Count separately the number of employees in the finance and research department.
select count(ssn) from employee55 where department_number =(select department_number from
dept where department_name='Finance');
select count(ssn) from employee55 where department_number=(select department_number from
dept where department_name ='Research');
//9. List out the employees based on their seniority.
select first_name,last_name,months_between(sysdate,birthday)/12 from employee55 order by
months_between(sysdate,birthday)/12 desc;
//10. List out the employees who works in ‘manufacture’ department group by first name
select first_name,ssn from employee55 where department_number=(select department_number
from dept where department_name='Manufacture');
Output