0% found this document useful (0 votes)
87 views9 pages

CSE2031 - Principle of Database Management Systems Lab Fall Semester 2021 - 2022 Lab Assignment - 2

This document outlines an assignment for a database management systems lab. It includes 19 exercises testing SQL operators and functions like SELECT, WHERE, GROUP BY, ORDER BY, COUNT, MIN, MAX, AVG, SUBSTR, REPLACE, LENGTH, and more. The exercises retrieve employee names and salaries, departments, group statistics, and perform string operations on table fields.

Uploaded by

Priyanka BVS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views9 pages

CSE2031 - Principle of Database Management Systems Lab Fall Semester 2021 - 2022 Lab Assignment - 2

This document outlines an assignment for a database management systems lab. It includes 19 exercises testing SQL operators and functions like SELECT, WHERE, GROUP BY, ORDER BY, COUNT, MIN, MAX, AVG, SUBSTR, REPLACE, LENGTH, and more. The exercises retrieve employee names and salaries, departments, group statistics, and perform string operations on table fields.

Uploaded by

Priyanka BVS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CSE2031 – Principle of Database Management Systems Lab

Fall Semester 2021 – 2022


Lab Assignment – 2
NAME: BVS PRIYANKA FACULTY: Dr .NATARAJAN P
REG.NO:20BDS0237 SLOT: L55+L56

Exercise: III
Operators and Functions
Aim: To understand different operators and types of function in SQL

1. Find the employee names whose salary lies in the range between 30000 and
70000.
SQL>select "First Name","Mid Name" ,"Last Name" , Salary from Employee
where Salary > 30000 and Salary <= 70000;

2.Find the employees who have no supervisor.


SQL> select "First Name","Mid Name","Last Name" from employee where
"Supervisor SSN" is null;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
3.Display the bdate of all employee s in the format ‘DDthMonthYYYY’.
SQL>select to char(Birthday, 'DDth Month YYYY') Birthday from Employee;

4. Display the employee names whose bdate is on or before 1978.


SQL> select "First Name", "Mid Name", "Last Name" from Employee where
Birthday <= date '1978-12-31';

5. Display the department name that starts with ’M’.


SQL>select "Department Name" from DEPT where "Department Name"
like'm%’;

6. Display the department names’ that ends with ‘E’.


SQL>select "Department Name" from DEPT where "Department Name"
like'%e’;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
7. Display the names of all the employees having supervisor with any of the
following SSN 123, 124.
SQL>SELECT first_name,mid_name,last_name from employee where
supervisor_ssn(123,124);

8. Display all the department names in upper case and lower case.
SQL>select upper(“Department Name”) from DEPT;

SQL>select lower(“Department Name”)from DEPT;

9. Display the first four characters and last four of the department names using
substring function.
SQL>select SUBSTR("Department Name", 1, 4) as "First fOUR",
SUBSTR("Department Name", -4) as "Last four" from DEPT;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
10. Display the substring of the Address (starting from 5th position to 11 th
position) of all employees.
SQL>select SUBSTR(Address, 5, 7) as address from Employee;

11. Display the Mgrstartdate on adding three months to it.


SQL>select ADD_MONTHS(ManagerStartDate, 3) AS MgrStartdate from
DEPT;

12. Display the age of all the employees rounded to two digits.
SQL>select ROUND((SYSDATE - Birthday)/365, 2) AS age FROM
Employee;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
13. Find the last day and next day of the month in which each manager has
joined.
SQl>select LAST_DAY(ManagerStartDate) as NEXT_DAY, Managerstartdate
+ 1 AS LAST_DAY FROM DEPT;

14. Print a substring from the string ‘Harini’.


SQL> select substr('Harini', 2, 4) as substring FROM DUAL;

15. Replace the string ‘ni’ from ‘Harini’ by ‘sh’.


SQL> select replace('Harini', 'ni', 'sh') from DUAL;

16. Print the length of all the department names.


SQL> select LENGTH("Department Name") From DEPT;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
17. Display the date after 10 months from current date.
SQL>SELECT ADD_MONTHS(SYSDATE, 10) FROM DUAL;

18. Display the next occurrence of Friday in this month.


SQL>select NEXT_DAY(SYSDATE, 'Friday') FROM DUAL where
NEXT_DAY(SYSDATE, 'Friday') <= date '2021-08-29';

19. Display the project location padded with **** on left side.
SQL> select LPAD("Project Location", LENGTH("Project Location") + 4,
'****') from Project;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
Exercise: IV
Group Functions
1. How many different departments are there in the ‘employee’ table.
SQL>select count(distinct department_number) from employee;

2. For each department display the minimum and maximum employee salaries.
SQL>select min(salary),max(salary) from employee group by
department_number;

3. Print the average annual salary.


SQL>select AVG(salary*12) from employee;

4. Count the number of employees over 30 age.


SQL> SELECT COUNT(DISTINCT SSN_NUMBER) FROM EMPLOYEE
WHERE(SYSDATE-BIRTHDAY)>30;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
5. Print the Department number and average salary of each department
SQL>select department_number, avg(salary) from department join employee
on employee.department_number=department.department_number group by
department_name;

6. List out all the department ids with their individual employees strength.
SQL> SELECT DEPARTMENT_NUMBER,COUNT(SSN_NUMBER) FROM
EMPLOYEE GROUP BY DEPARTMENT_NUMBER;

7. Display the department number which contains more than 2 employees.


SQL> SELECT DEPARTMENT_NUMBER FROM EMPLOYEE GROUP BY
DEPARTMENT_NUMBER HAVING (COUNT(SSN_NUMBER)>2);

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
8. Calculate the average salary of employees by department and age
SQL> SELECT AVG(SALARY) FROM EMPLOYEE GROUP BY
(DEPARTMENT_NUMBER);
SQL> SELECT AVG(SALARY) FROM EMPLOYEE GROUP BY
(SYSDATE-BIRTHDAY);

9. List out the employees based on their seniority.


SQL>SELECT first_name,mid_name,last_name from employee order by
(SYSDATE-BIRTHDAY)DESC;

This study source was downloaded by 100000808246774 from CourseHero.com on 01-19-2022 02:19:47 GMT -06:00

https://www.coursehero.com/file/118745057/pdms-lab-da-2pdf/
Powered by TCPDF (www.tcpdf.org)

You might also like