Professional Documents
Culture Documents
DBMS Lab Assignment 3 (SQL)
DBMS Lab Assignment 3 (SQL)
DBMS Lab Assignment 3 (SQL)
ASSIGNMENT - 3
1. Write a query to list all employees (Fname and Lname) who work in the
ADMINISTRATION department, and whose managers' name starts with ‘M.’
Soln.
SELECT Fname, Lname
FROM Employee
WHERE Ssn
IN
(
SELECT Mgr_ssn
FROM Department
WHERE Department = 'Administration'
AND Mgr_ssn IN
(
SELECT Super_ssn
FROM Employee
WHERE Fname LIKE 'M%'
); )
2. Write a query to find all employees (Fname and Lname) who have at least one
dependent born between 01.01.2010 and 01. 01. 2014.
DBMS (CS-612)
ASSIGNMENT - 3
3. Write a query to output the number of employees whose names and their
managers’ names start with any alphabet from {‘A’, ‘B’, ‘C’, ‘D’}.
4. Write a query to list all employees (Fname and Lname) who do not work in the
ADMINISTRATION department and whose names do not start with ‘M’.
DBMS (CS-612)
ASSIGNMENT - 3
5. Write a query to list all male employees (Fname and Lname) who work in the
`SEMICONDUCTOR` project in KOLKATA under the RESEARCH department.
DBMS (CS-612)
ASSIGNMENT - 3
6. Write a query to list the number of employees who work in the ADMINISTRATION
department in the MANAGER POST; locations should make groups to show the
results.
DBMS (CS-612)
ASSIGNMENT - 3
7. Write a query to list the names of all employees who work in the
ADMINISTRATION department in the MANAGER post; the result should be
grouped by sex first and then by locations.
8. Write a query to list all the employees who are less than 45 years of age but are
managers. Now, generate the complement of the previous output.
9. Write a query to generate a report about the company's cost for salary purposes
department-wise and then location-wise.
DBMS (CS-612)
ASSIGNMENT - 3
Soln. SELECT e.Fname, e.Lname, e.Ssn, e.Dno, d.Department, dl.Dlocation, e.Salary FROM
employee e
LEFT JOIN department d
ON e.Dno = d.Dnumber
LEFT JOIN dept_locations dl
ON e.Dno = dl.Dnumber
GROUP BY d.Department, dl.Dlocation;
10. Write a query to list the Fname, Lname of all employees who work in a project
where at least four employees are attached.
11. List the employees who do not belong to department name RESEARCH.
DBMS (CS-612)
ASSIGNMENT - 3
12. Select the employees getting a salary greater than the average salary of all the
employees in that department.
13. Write a query to find the department with the highest number of employees.
DBMS (CS-612)
ASSIGNMENT - 3
14. Write a query to list all project numbers involving an employee whose last name
is 'Narayan’ either as a worker or as a department manager who controls the
project.
15. Output the location and department number for all projects having more than five
employees of age greater than or equal to 50 Yrs.
Employee –
CREATE TABLE Employee(
Fname VARCHAR(20),
Minit CHAR,
Lname VARCHAR(20),
Ssn BIGINT PRIMARY KEY,
Bdate DATE,
Address TINYTEXT,
Sex CHAR,
Salary MEDIUMINT,
Super_ssn BIGINT,
Dno CHAR
);
('James', 'E', 'Borg', 888665555, '1937-11-10', '450 Stone, Houston, TX', 'M', 55000, NULL,
'1');
Department –
CREATE TABLE Department(
Department VARCHAR(20),
Dnumber CHAR PRIMARY KEY,
Mgr_ssn BIGINT,
Mgr_start_date DATE
);
VALUES
('Research', '5', 333445555, '1988-05-22'),
('Administration', '4', 987654321, '1995-01-01'),
('Headquarters', '1', 888665555, '1981-06-19');
Dept_Locations – CREATE
TABLE Dept_Loacations(
Dnumber CHAR,
DBMS (CS-612)
ASSIGNMENT - 3
Dlocation VARCHAR(10)
);
Works_On – CREATE
TABLE Works_On(
Essn BIGINT,
Pno CHAR(2),
Hours DECIMAL(3, 1)
);
Project –
CREATE TABLE Project(
Pname VARCHAR(20),
Pnumber CHAR(2) PRIMARY KEY,
Plocation VARCHAR(10),
Dnum CHAR
DBMS (CS-612)
ASSIGNMENT - 3
);
Dependent –
CREATE TABLE Dependent(
Essn BIGINT,
Dependent_name VARCHAR(15),
Sex CHAR,
Bdate DATE,
Relationship VARCHAR(10)
);
VALUES
(333445555, 'Alice', 'F', '1986-04-05', 'Daughter'),
(333445555, 'Theodore', 'M', '1983-10-25', 'Son'),
(333445555, 'Joy', 'F', '1958-05-03', 'Spouse'),
(987654321, 'Abner', 'M', '1942-02-28', 'Spouse'),
(123456789, 'Michael', 'M', '1988-01-04', 'Son'),
(123456789, 'Alice', 'F', '1988-12-30', 'Daughter'),
(123456789, 'Elizabeth', 'F', '1967-05-05', 'Spouse');