Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 2.1

Student Name: Ankit Vashisth UID: 22BCS13378


Branch: CSE Section/Group: 707-A

Semester: 4th Date of Performance: 13-03-2024

Subject Name: DBMS Subject Code: 22CSH-254

1. Aim: (i) Create a relation employee with following attributes emp_no NOT
NULL INT, emp_name VARCHAR(10), job VARCHAR(9), hier_date INT,
dept_number INT, age INT, e_salary INT
a) List minimum , maximum and average salary of employee.
b) What is difference between maximum and minimum salary of employee
in the organisation.
c) Display all emp_name and salary whose salary is greater than
minimum salary of the company and job tittle starts with "M". d)
Display lowest paid employee details under each manager.
(ii) Write a PL/SQL code to print table of a number.

2. Source Code:
(i)
CREATE TABLE employee (
emp_no INT NOT NULL,
emp_name VARCHAR(30),
job VARCHAR(20),
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
hier_date INT,
dept_number INT, age INT,
e_salary INT, manager_id
INT, PRIMARY KEY
(emp_no)
);
INSERT INTO employee VALUES
(1, 'Gaurav', 'Manager', 2022, 101, 35, 60000, NULL),
(2, 'Tushar', 'Manager', 2021, 102, 32, 58000, NULL),
(3, 'Deep', 'Developer', 2018, 101, 28, 50000, 1),
(4, 'Shorey', 'Marketer', 2010, 102, 30, 52000, 2),
(5, 'Mohan', 'Manager', 2022, 103, 40, 62000, NULL),
(6, 'Somya', 'Developer', 2022, 103, 27, 48000, 5),
(7, 'Mahi', 'Marketer',2022, 101, 29, 51000, 1);

(i) SELECT MIN(e_salary) AS min_salary,


MAX(e_salary) AS max_salary,
AVG(e_salary) AS avg_salary
FROM employee;

(ii) SELECT MAX(e_salary) - MIN(e_salary) AS salary_difference FROM


employee;

(iii) SELECT emp_name, e_salary


FROM employee
WHERE e_salary > (SELECT MIN(e_salary) FROM employee)
AND job LIKE 'M%';
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
(iv) SELECT manager.emp_name AS manager_name,
employee.emp_name AS lowest_paid_employee, employee.e_salary
AS lowest_salary
FROM employee
JOIN employee AS manager ON employee.manager_id = manager.emp_no
WHERE employee.e_salary = (
SELECT MIN(e_salary) FROM
employee
WHERE manager_id = manager.emp_no
);

3. Screenshot of Outputs:

(a) First output:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

(b) Second ouput:

(c) Third output:


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

(c) Fourth output:

(d)Fourth output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
(ii) PL/SQL code to print table of a number:

declare
num int := 5;
Begin
For i in 1 .. 10 loop
dbms_output.put_line(num*i);
end loop;
end;

(ii) Output :

You might also like