Professional Documents
Culture Documents
21bce0400 Ass2
21bce0400 Ass2
Assessment -2
Output:
2) Find the employee names whose salary lies in the range between 30000 and
70000.
Query :
SELECT First_Name, Last_Name
FROM Employee
WHERE Salary >= 30000 AND Salary <= 70000;
Output:
Output:
4) Display the bdate of all employee s in the format ‘DDthMonthYYYY’.
Query:
SELECT EXTRACT(DAY FROM birthday) || 'th' || TO_CHAR(birthday, 'MonthYYYY') AS
Birth_day
FROM Employee;
Output:
Output:
Output:
8) Display the department names’ that ends with ‘E’.
Query:
SELECT department_name
FROM Dept
WHERE department_name LIKE '%e';
Output:
9) Display the names of all the employees having supervisor with any of the
following SSN 554433221, 333445555.
Query:
SELECT first_name || ' ' || mid_name || ' ' || last_name AS employee_name
FROM Employee
WHERE SSN_NUMBER in(554433221, 333445555);
Output:
10) Display all the department names in upper case and lower case
Query:
SELECT UPPER(department_name) AS department_name_upper,
LOWER(department_name) AS department_name_lower
FROM dept;
Output:
11) Display the first four characters and last four of the department names
using ltrim and rtrim.
Query:
SELECT LTRIM(SUBSTR(department_name, 1, 4)) AS first_four_chars,
RTRIM(SUBSTR(department_name, -4)) AS last_four_chars
FROM dept;
Output:
12) Display the substring of the Address (starting from 5th position to 11th
position) of all employees.
Query:
SELECT SUBSTR(Address, 5, 7) AS address_substring_5to11
FROM Employee;
Output:
14) Display the age of all the employees rounded to two digits.
Query:
SELECT ROUND((SYSDATE - BIRTHDAY) / 365.25, 2) AS AGE
FROM Employee;
Output:
15) Find the last day and next day of the month in which each manager has
joined.
Query:
SELECT LAST_DAY(MANAGERSTARTDATE) AS
LAST_DAY_OF_MONTH, MANAGERSTARTDATE + INTERVAL '1' DAY
AS NEXT_DAY
FROM dept;
Output:
EXERCISE 2
For the relational schema given as part of Assessment – 1, write
the SQL queries using Group Functions to get the following
information.
Query:
FROM employee;
Output:
Query:
SELECT DEPARTMENT_NUMBER, MIN(SALARY) AS MIN_SALARY,
MAX(SALARY) AS MAX_SALARY
FROM Employee
GROUP BY DEPARTMENT_NUMBER;
Output:
Query:
FROM Employee;
Output:
Query:
Query:
GROUP BY d.DEPARTMENT_NAME;
Output:
6) Display the department name which contains more than 30
employees.
Query:
Output:
Query:
SELECT DISTINCT DEPARTMENT_NUMBER, ROUND(MONTHS_BETWEEN(SYSDATE,BIRTHDAY)/12) AS
AGE_IN_YEARS, AVG(SALARY)
Output:
8) Count separately the number of employees in the finance and
research department.
Query:
FROM dept
GROUP BY DEPARTMENT_NAME;
Output:
Query:
SELECT E.FIRST_NAME,E.LAST_NAME
FROM EMPLOYEE E
Query:
FROM EMPLOYEE E
GROUP BY E.FIRST_NAME;
Output: