MidtermExam TestPaper IM2
MidtermExam TestPaper IM2
SECTION:
General Instructions
Create a database that contains relevant data as described below and answer the
provided query questions. You may use basic SQL functions and keywords like
SELECT, FROM, JOIN, WHERE, GROUP BY, COUNT, and ORDER BY. Please
ensure that your queries are both efficient and capable of delivering accurate results.
Additionally, kindly provide a query for each question.
Functions:
DATEDIFF(interval, date1, date2)
Consider a simplified schema for a school employee system with the following tables:
// employee information
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
DateOfBirth DATE,
Gender VARCHAR(10),
DepartmentID INT,
PositionID INT,
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID),
FOREIGN KEY (PositionID) REFERENCES Positions(PositionID)
);
// department information
CREATE TABLE Departments (
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(100)
);
// position information
CREATE TABLE Positions (
PositionID INT PRIMARY KEY,
PositionTitle VARCHAR(100)
);
(1, 'CCS'),
(2, 'CA'),
(3, ‘CAS');
Insert positions
(1, 'Instructor'),
(2, 'Dean'),
(3, 'Professor');
Insert employees
YOUR ANSWER:
Sample Output:
2. Create a query that lists all leave requests with their corresponding employee names and
statuses.
YOUR ANSWER:
Sample OUTPUT:
Sample output:
Department_Nam Employee_Count
e
CCS 7
CAS 15
CED 22
4. Create a query that find the total number of pending leave requests.
YOUR ANSWER
Sample output:
Total_Pending_Leave_reuqests
2
5. Create a query that lists employees who are currently on leave.
YOUR ANSWER:
Sample output:
6. Create a query that find the department with the highest number of employees.
YOUR ANSWER:
Sample Output:
Department Employee_Count
Name
CCS 3
7. Create a query that lists all employees who have not taken any leave.
YOUR ANSWER:
Sample Output:
Sample Output:
9. A query that Calculate the average number of days taken for leave by each employee.
Sample Output: