0% found this document useful (0 votes)
6 views

MidtermExam TestPaper IM2

Uploaded by

anamae.amorin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MidtermExam TestPaper IM2

Uploaded by

anamae.amorin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

NAME:

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)

Create a new database named “Removal’’

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)
);

// employee leave requests


CREATE TABLE LeaveRequests (
RequestID INT PRIMARY KEY,
EmployeeID INT,
LeaveType VARCHAR(50),
StartDate DATE,
EndDate DATE,
Status VARCHAR(20),
FOREIGN KEY (EmployeeID) REFERENCES Employees(EmployeeID)
);
Insert departments (colleges of school)

(1, 'CCS'),

(2, 'CA'),

(3, ‘CAS');

Insert positions

(1, 'Instructor'),

(2, 'Dean'),

(3, 'Professor');

Insert employees

(101, 'John', 'Doe', '1980-05-10', 'Male'), -- CCS Instructor

(102, 'Alice', 'Smith', '1975-08-20', 'Female'), -- CAS


Instructor

(103, 'Michael', 'Williams', '1982-03-15', 'Male'), -- CA


Professor

(104, 'Emma', 'Johnson', '1990-11-28', 'Female'), -- CCS, Dean

(105, 'Sophia', 'Brown', '1988-07-02', 'Female'), -- CAS,


Professor

(106, 'David', 'Miller', '1977-09-18', 'Male',), -- CA, Dean

(107, 'Olivia', 'Wilson', '1985-04-25', 'Female'), -- CCS,


Professor

(108, 'Liam', 'Davis', '1983-01-09', 'Male'), --CAS, Instructor

(109, 'Ella', 'Martinez', '1986-06-30', 'Female'), -- CA,


Professor

(110, 'Noah', 'Taylor', '1989-10-14', 'Male'); -- CAS, Dean


1. Create a query that lists all employees along with their department and position titles.

YOUR ANSWER:

Sample Output:

First_Name Last_Name Department_Name Position_Title


Cecilia Benlota College of Computer Dean
Studies
Ana Mae Amorin College of Computer Instructor
Studies

2. Create a query that lists all leave requests with their corresponding employee names and
statuses.
YOUR ANSWER:

Sample OUTPUT:

Request_I FirstName LastName Leave_Type Start_date End_date Status


D
101 Sheena Sabado Sick 2024-01- 2024-01- Approved
Mae 01 07
102 Jessebel Nemenzo Vacation 2024-04- 2024-04- Pending
20 22
3. Create a query that count the number of employees in each department.
YOUR ANSWER:

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:

First_Name Last_Name Leave_Type Start_Date End_Date


Jason Diputado Sick 2024-04-26 2024-04-30

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:

Department_name First__Name Last_Name


CAS Jason Diputado
8. Create a query that retrieves the total number of male and female employees in each of
the department whose age is ranging from 20 to 25.

Sample Output:

Department_Name Gender Total_Employees


CCS Male 3
CCS Female 1
CA Male 2
CA Female 1
CAS Male 3
CAS Female 0

9. A query that Calculate the average number of days taken for leave by each employee.
Sample Output:

FirstName LastName AverageLEaveDays


Cherry Gil 5.0
Andrew Mores 2.5

You might also like