CSE2031 - Principle of Database Management Systems Lab Fall Semester 2021 - 2022 Lab Assignment - 2
CSE2031 - Principle of Database Management Systems Lab Fall Semester 2021 - 2022 Lab Assignment - 2
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;
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;
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;
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;
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;
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;
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;
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;
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);
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)