You are on page 1of 37

THE GEORGE WASHINGTON UNIVERSITY – ISTM 6215 – GROUP PROJECT

Rental Car Inventory
Relational Database System
Research

Alana Hill
Alexander J. Singleton
Gabriela Marchiani
Kangkyu Lee
Thomas Lebeau

April 30, 2017

The George Washington University
School of Business
 
 
 
 
 
 
Our Mission Statement 4

Mission Objectives 4

Requirements 4

Entity Relationship Diagram (ERD) 5
Attribute Modeling 6
Tables 6
Accessory (GPS, etc.) 6
Customer 6
Employee 6
Rental Office Location 6
Reservation 7
Vehicle 7

Post-Mortem 8

References 10

Appendix 11
Entity Relationship Diagram 11
Relational Database Model 12
Queries 13
Number of Rater Per Location 13
Number of Employee Positions 14
Number of Employee Positions 15
Total Revenue Collected Per State 16
Models Available Within Range 17
Subquery to View Reservation with the Oldest Date 18
Display Customer Reservations with Make and Model of Vehicle 19
Vehicle Maintenance Record Count Completed by Each Employee 20
Total Reservations of Each Rental Office by Sales in Descending Order 21
Total Reservations of Each Rental Office by Sales in Descending Order 22
Employee Information Grouped by Last Name 23
Total Cost of Reservation by Customer ID and Rental Vehicle VIN# 24
Maintenance Log Ordered by Date 25
Reservation Date and Cost According to Rental Office Location 26
Cost of Each Accessory According to Descending Order 27
Report Displaying Customer, Reservation and Vehicle Information 28
Prices of Reservations with the Accessory Cost Added 30
Vehicle Age with Model and Make 31
Employee Count by Rental Office 32
Show Vehicles with Maintenance Records 33
Reservation Count by Office Location 34
Customer Accessory Selection 35
Number of Rental Days 37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1. Our Mission Statement
a. Our mission is to satisfy our customer’s rental car needs while delivering 
the best quality, service and value; we believe the ideal system is a 
human-centered user-experience modeled according to a consistent 
object-oriented model from the front-end all the way to the back-end of 
the database.1  Concordantly, we believe both the entity relationship 
diagram and relational database-model specifications required by the 
rental-car management inventory system will seek to: 
i. Proactively maintain and monitor the database system to prevent 
any potential issues.2 
ii. Accurately diagnose and forecast the database system health and 
capacity to maximize return on investment for the rental-car 
inventory management system and promptly respond to the 
stakeholder’s support request(s) to remove any work bottleneck on 
DBA side.3 
iii. Persistently seek innovative ways to improve DBA work efficiently 
yet effectively.4 
2. Mission Objectives
a. Check vehicle inventory by location 
b. Associate customer information with rental car reservation 
c. Track rental car inventory 
d. Track rental car maintenance 
e. Track accessory inventory 
3. Requirements
a. A rental car company wants to monitor vehicle-inventory and 
reservations. 
b. For each vehicle, we will record Make, Model, Year, Color, LicensePlate, 
Mileage and VIN. 
c. For each customer, we assign a unique-identifier (ID), FirstName, 
LastName, PhoneNumber, EmailAddress, Driver’s License, and 
RewardsNumber. 
d. For each rental-office location, we will assign unique identifier (ID) for 
RentalOfficeID, StreetAddress, City, State and ZipCode. 

1
​Singleton, Alexander J., and Shaulinator via ​Database Admininstrators StackExchange
2
​Singleton, Alexander J., and Shaulinator via ​Database Admininstrators StackExchange
3
​Singleton, Alexander J., and Shaulinator via ​Database Admininstrators StackExchange
4
​Singleton, Alexander J., and Shaulinator via ​Database Admininstrators StackExchange
e. Every time a customer reserves a car, the reservation will be assigned a 
unique-identifier (ID), Pick-up Date, ReturnDate, DailyRate, Total, 
CustomerID and RentalOfficeID. 
f. A customer can reserve many cars, but must have at least one rental 
reservation. 
g. A car may be reserved by many customers, or none at all. 
h. A maintenance-log will record VehicleID, Procedure, Date. 
i. The rental-company will offer accessories for each customer-reservation. 
For each accessory, we will maintain a unique-identifier called 
SerialNumber, type, cost, and quantity which will correspond to 
RentalOfficeID, CustomerID, VehicleID and ReservationID. 
j. A Rental Office Location can have many vehicles, but must have at least 
one. 
k. A Vehicle may be used by multiple Rental Office Locations, but must have 
at least one. 
l. A Vehicle may have many reservations, or none at all.  
m. A Rental Office Location can have many employees, but must have at 
least one. 
n. An Employee can work at multiple Rental Office Locations, but must work 
at at least one. 
o. A Rental Office Location can have multiple Reservations, and may have 
none. 
p. A Reservation must have one Rental Office Location. 
q. A Reservation must have one vehicle.  
r. A Reservation may have one or more accessories, but may have none. 
s. An Accessory can be used in multiple Reservations, or none at all. 
t. Maintenance must be completed by at least one Employee, but can be 
completed by multiple employees 
u. The attribute ‘vehicle age’ is calculated by subtracting vehicle model year 
from the date of reservation.  
4. Entity Relationship Diagram (ERD)
a. An Employee may perform multiple maintenance activities, or they may 
not perform any. 
b. A Rental Office Location may have multiple customers, or none at all 
c. A Customer may use multiple Rental Office Locations, but must use at 
least one (five entities and at least four binary relationships).  At least one 
of the relationships should be many to many.  Show all attributes of all 
entities. 
d. We invite review of the ERD modeled at [Lucid Charts](link). 
e. Attribute Modeling
i. Bold​ - Foreign Key 
ii. Underline​ - Potential Primary Key 
iii. Tables
1. Accessory (GPS, etc.)
a. Serial Number 
b. Type 
c. Cost 
d. Quantity 
2. Customer
a. CustomerID 
b. Customer FName 
c. Customer LName 
d. CustomerEmail 
e. Driver’s License Number (U) 
f. RewardNumber (O) 
3. CustomerPhoneNo 
a. CustomerID (FK) 
b. CustomerPhoneNo 
4. Employee
a. EmployeeID 
b. EmployeeFName 
c. EmployeeLName 
d. Title 
e. SSN (U​) 
5. Employing 
a. RentalOfficeID (FK) 
b. EmployeeID (FK) 
6. Includes 
a. SerialNumber (FK) 
b. ReservationID (FK) 
7. Maintenance Log 
a. EmployeeID (FK​) 
b. VIN (FK) 
c. Date 
d. Procedure 
8. Rental Office Location
a. RentalOfficeID 
b. StreetAddress 
c. City 
d. State 
e. ZipCode 
9. Reserves 
a. SerialNumber (FK) 
b. ReservationID (FK​) 
10. Reservation
a. ReservationID 
b. Date(s) 
c. Daily Rate 
d. Total 
e. CustomerID (FK) 
f. RentalOfficeID (FK) 
11. Vehicle
a. VIN
b. Make 
c. Model 
d. Year 
e. Color 
f. License Plate (U) 
g. Mileage 
 
Post-Mortem 
 
● Our initial models included two relations that had identical names: “Reserves.” 
This was a simple oversight that merely required us to alter the name of the 
relation between Accessory and Reservation to “Includes.” 
● Our initial design called for a ternary relationship between Vehicle, Accessory, 
and Reservation tables. However, after discussion we decided to divide the 
single relation out into two separate relations, one between Vehicle and 
Reservation tables, and one between Accessory and Reservation tables. Our 
logic behind this decision is that it is fully possible for a reservation to not have 
any accessories attached to it, and by automatically including a column for the 
accessory serial number in the relation table could result in a significant amount 
of null values for that column, which would have served as a foreign key. In 
dividing the two relations into separate tables, we were able to ensure that there 
would be no null foreign key values. 
● The initial design only allowed for a single phone number to be assigned to each 
customer. However, after discussion it was decided that this would not be 
sufficient, as multiple contact numbers are common. To solve for this, we added 
an additional table that is linked to the Customer table, using CustomerID as a 
foreign key to incorporate multiple phone numbers. Our initial implementation of 
this table was incorrect though, as there was no primary key assigned to the 
table. After testing the initial table CREATE and data INSERT statements, we 
discovered our error and established the phone number column as the primary 
key column. 
● At the start, we had misstated the requirements necessary for how tracking 
vehicle maintenance would work. We had incorrectly assumed a one to many 
relationship between the vehicle and the employee, thus overlooking the need 
for a relational table that linked these two entities. Once the requirements had 
been corrected, we also designed the Maintenance_Log table, that would store 
the necessary, and relevant data, for tracking maintenance updates performed 
on the vehicles in question. 
● Our updated design called for a column labelled “Procedure” in the 
Maintenance_Log Table. During our design phase though, we did not realize 
that “Procedure” is a reserved term in SQL, and it would not be possible for us 
to use this title for the column. After troubleshooting our CREATE statement, we 
discovered the error, and had to backtrack and update our design to re-name 
this column “Maintenance_Procedure.” 
● Our updated design was also lacking another critical piece of data in regards to 
the Maintenance_Log table: the primary key. After experiencing some issues in 
creating and populating the table, we realized that each individual procedure 
would needs its own unique identifier, and added in the Maintenance_ID 
column. 
● In defining the requirements for our Reservation table, we had specified the 
need to store data that would allow for the calculation of total cost of the 
reservation, and decided to do so by tracking the dates of the rental and the 
daily cost. However, in our initial design, the table only had a single column for 
reservation dates. Storing this data in a single column would not have allowed 
us to easily track the total number of days that the reservation spanned, so we 
had to update the database to hold an additional column, thus allowing us to 
split the dates into a Pick_Up_Date column and a Return_date column. 
 
 
 
 
 
References
1. Singleton, Alexander J., and Shaulinator. ​"What is a database mission-statement?" Sql -
What is a database mission-statement? - Database Administrators Stack Exchange​:
[https://dba.stackexchange.com/questions/165669/what-is-a-database-mission-statemen
t]. Stack Exchange: Database Administrators, 28 Feb. 2017. Web. 08 Mar. 2017.
Appendix

Entity Relationship Diagram
Relational Database Model
Queries
The following code-blocks are MySQL-code prefaced with comments explaining the subsequent
MySQL-query above the next code-block containing the terminal-output. For our top-5
selections, please see the attached PowerPoint presentation included within the compressed
final-deliverable file.

Number of Rater Per Location

-- This query will count all records within the Daily_Rate column using the
count-function returning the number of records within the RESERVATION-table
grouped by RentalOfficeID, which will then be displayed as an alias-column,
"Number of rates per location."

SELECT​ Daily_Rate, ​count​(*) ​AS​ ​"Number of rates per location"
FROM​ RESERVATION
GROUP​ ​BY​ RentalOfficeID;

Number of Rater Per Location Terminal Output

mysql> ​SELECT​ Daily_Rate, ​count​(*) ​AS​ ​"Number of rates per location"
-> ​FROM​ RESERVATION
-> ​GROUP​ ​BY​ RentalOfficeID;
+​------------+------------------------------+
| Daily_Rate | Number of rates per location |
+​------------+------------------------------+
| 95.00 | 1 |
| 125.00 | 2 |
| 125.00 | 2 |
| 80.00 | 1 |
+​------------+------------------------------+
4 rows in ​set​ (​0.08​ sec)
Number of Employee Positions

-- This query will count all of the employed positions by selecting the
Title Column from the Employee-table using the COUNT method in conjunction
with the DISTINCT method to effectively
-- count all unique last-names then grouping the count of unique last names
corresponding to those employee-positions by Title from the EMPLOYEE-Table
displayed in an alias-table "COUNT OF EMPLOYEES."

SELECT​ TITLE ​AS​ ​"TITLE"​, ​COUNT​(​DISTINCT​ EmployeeLNAME)
AS​ ​"Number of employee-positions"
FROM​ EMPLOYEE ​GROUP​ ​BY​ TITLE;

Number of Employee Positions Terminal Output

mysql> ​SELECT​ TITLE ​AS​ ​"TITLE"​, ​COUNT​(​DISTINCT​ EmployeeLNAME)
-> ​AS​ ​"Number of employee-positions"
-> ​FROM​ EMPLOYEE ​GROUP​ ​BY​ TITLE;
+​--------------------------+------------------------------+
| TITLE | Number of employee-positions |
+​--------------------------+------------------------------+
| Customer Care Specialist | 4 |
| Mechanic | 4 |
| Office Manager | 4 |
+​--------------------------+------------------------------+
3 rows in ​set​ (​0.07​ sec)

mysql>
Number of Employee Positions

-- The query utilizes the SOUNDEX-method to find a customer that sounds
phoentically similar to "Zitanna" (e.g. "Find name that sounds like using
Zitanna").
-- According to Wikipedia, "SOUNDEX was developed in 1985 by genealogist
Gary Mokotoff and later improved by genealogist Randy Daitch because of
problems they encountered
-- while trying to apply the Russell Soundex to Jews with Germanic or
Slavic surnames (such as Moskowitz vs. Moskovitz or Levine vs. Lewin)."
(https://en.wikipedia.org/wiki/Soundex)

SELECT​ CustomerFName
FROM​ CUSTOMER
WHERE​ ​SOUNDEX​(CustomerFName) = ​SOUNDEX​(​'Zitanna'​);

Number of Employee Positions Terminal Output

mysql> ​SELECT​ CustomerFName
-> ​FROM​ CUSTOMER
-> ​WHERE​ ​SOUNDEX​(CustomerFName) = ​SOUNDEX​(​'Zitanna'​);
+​---------------+
| CustomerFName |
+​---------------+
| Zatanna |
+​---------------+
1 row in ​set​ (​0.07​ sec)
Total Revenue Collected Per State

-- This query will display the total-revenue collected per state by
utiliziing an implicit-join format in addition to alias tables to
effectively displaying the total-revenue collected by state corresponding
to the "RentalOfficeID" column contained within the two separate tables,
joining or "zipping-up" the data separated between the tables. According
to OracleSQL blog-spot, the "implicit join notation" simply lists the
tables for joining.
(http://sql-plsql.blogspot.com/2011/02/explicit-implicit-sql-joins.html)

SELECT​ STATE, Total
FROM​ RENTAL_OFFICE_LOCATION r,
RESERVATION i
WHERE​ r.RentalOfficeID=i.RentalOfficeID
ORDER​ ​BY​ Total;

Total Revenue Collected Per State Terminal Output

mysql> ​SELECT​ STATE, Total
-> ​FROM​ RENTAL_OFFICE_LOCATION r,
-> RESERVATION i
-> ​WHERE​ r.RentalOfficeID=i.RentalOfficeID
-> ​ORDER​ ​BY​ Total;
+​-------+---------+
| STATE | Total |
+​-------+---------+
| OR | 285.00 |
| NY | 380.00 |
| CO | 575.00 |
| CO | 875.00 |
| NY | 875.00 |
| ME | 1120.00 |
+​-------+---------+
6 rows in ​set​ (​0.06​ sec)
Models Available Within Range

-- The query should only display the models within the above range, which
this case should be two different
-- makes and the two corresponding models accordingly: "available make and
models with mileage at least 10,000 miles but less than 20,000 miles."

SELECT​ Make, ​Model
FROM​ VEHICLE
WHERE​ Mileage >= ​10000
AND​ Mileage < ​20000​;

Models Available Within Range Terminal Output

mysql> ​SELECT​ Make, ​Model
-> ​FROM​ VEHICLE
-> ​WHERE​ Mileage >= ​10000
-> ​AND​ Mileage < ​20000​;
+​---------+----------+
| Make | Model |
+​---------+----------+
| Hyundai | Veloster |
| Chevy | Tahoe |
+​---------+----------+
2 rows in ​set​ (​0.06​ sec)
Subquery to View Reservation with the Oldest Date

-- This query uses a subquery to view a reservation with the oldest date.

SELECT​ * ​FROM​ RESERVATION
WHERE​ Pick_Up_Date = (​SELECT​ ​MIN​(Pick_Up_Date) ​FROM​ RESERVATION);

Subquery to View Reservation with the Oldest Date Terminal Output

mysql> ​SELECT​ * ​FROM​ RESERVATION
-> ​WHERE​ Pick_Up_Date = (​SELECT​ ​MIN​(Pick_Up_Date) ​FROM​ RESERVATION);
+​---------------+--------------+-------------+------------+--------+-------
-----+----------------+
| ReservationID | Pick_Up_Date | Return_Date | Daily_Rate | Total |
CustomerID | RentalOfficeID |
+​---------------+--------------+-------------+------------+--------+-------
-----+----------------+
| 2 | 2017-03-01 | 2017-03-03 | 95.00 | 285.00 |
2 | 1 |
+​---------------+--------------+-------------+------------+--------+-------
-----+----------------+
1 row in ​set​ (​0.06​ sec)
Display Customer Reservations with Make and Model of Vehicle

-- This query will display customer reservations with the make and model
of vehicle using three inner joins.

SELECT​ CUSTOMER.CustomerID, CUSTOMER.CustomerFname ​AS​ First_Name,
CUSTOMER.CustomerLname ​AS​ Last_Name, RESERVES.VIN, VEHICLE.Make,
VEHICLE.Model
FROM​ (((CUSTOMER
INNER​ ​JOIN​ RESERVATION ​ON​ CUSTOMER.CustomerID = RESERVATION.CustomerID)
INNER​ ​JOIN​ RESERVES ​ON​ RESERVATION.ReservationID = RESERVES.ReservationID)
INNER​ ​JOIN​ VEHICLE ​ON​ RESERVES.VIN = VEHICLE.VIN);

Display Customer Reservations with Make and Model of Vehicle Terminal Output

mysql> ​SELECT​ CUSTOMER.CustomerID, CUSTOMER.CustomerFname ​AS​ First_Name,
CUSTOMER.CustomerLname ​AS​ Last_Name, RESERVES.VIN, VEHICLE.Make,
VEHICLE.Model
-> ​FROM​ (((CUSTOMER
-> ​INNER​ ​JOIN​ RESERVATION ​ON​ CUSTOMER.CustomerID =
RESERVATION.CustomerID)
-> ​INNER​ ​JOIN​ RESERVES ​ON​ RESERVATION.ReservationID =
RESERVES.ReservationID)
-> ​INNER​ ​JOIN​ VEHICLE ​ON​ RESERVES.VIN = VEHICLE.VIN);
+​------------+------------+-------------+------------+---------+----------+
| CustomerID | First_Name | Last_Name | VIN | Make | Model |
+​------------+------------+-------------+------------+---------+----------+
| 1 | John | Constantine | 11111AAAAA | Honda | Accord |
| 2 | Hal | Jordan | 22222BBBBB | Hyundai | Veloster |
| 3 | Barry | Allen | 33333CCCCC | Chevy | Tahoe |
| 6 | Zatanna | Zatara | 33333CCCCC | Chevy | Tahoe |
| 4 | Dinah | Lance | 44444DDDDD | Audi | A4 |
| 5 | Felicity | Smoak | 55555EEEEE | Dodge | Charger |
+​------------+------------+-------------+------------+---------+----------+
6 rows in ​set​ (​0.07​ sec)
Vehicle Maintenance Record Count Completed by Each Employee

-- This query counts the maintenance records that each employee has
completed.

SELECT​ EMPLOYEE.EmployeeID, EMPLOYEE.EmployeeFname ​AS​ First_Name,
EMPLOYEE.EmployeeLname ​AS​ Last_Name, ​COUNT​(MAINTENANCE_LOG.Maintenance_ID)
AS​ Maintenance_Count
FROM​ EMPLOYEE
INNER​ ​JOIN​ MAINTENANCE_LOG ​ON​ EMPLOYEE.EmployeeID =
MAINTENANCE_LOG.EmployeeID ​GROUP​ ​BY​ EMPLOYEE.EmployeeID;

Vehicle Maintenance Record Count Completed by Each Employee Terminal Output

SELECT​ EMPLOYEE.EmployeeID, EMPLOYEE.EmployeeFname ​AS​ First_Name,
EMPLOYEE.EmployeeLname ​AS​ Last_Name, ​COUNT​(MAINTENANCE_LOG.Maintenance_ID)
AS​ Maintenance_Count
-> ​FROM​ EMPLOYEE
-> ​INNER​ ​JOIN​ MAINTENANCE_LOG ​ON​ EMPLOYEE.EmployeeID =
MAINTENANCE_LOG.EmployeeID ​GROUP​ ​BY​ EMPLOYEE.EmployeeID;
+​------------+------------+-----------+-------------------+
| EmployeeID | First_Name | Last_Name | Maintenance_Count |
+​------------+------------+-----------+-------------------+
| 9 | Bruce | Wayne | 1 |
| 10 | Clark | Kent | 1 |
| 11 | Lex | Luthor | 1 |
| 12 | Edward | Nygma | 1 |
+​------------+------------+-----------+-------------------+
4 rows in ​set​ (​0.07​ sec)
Total Reservations of Each Rental Office by Sales in Descending Order

--This query adds the total rervations of each rental office by sales in
descending order. The SUM function, a join, group by and order by are used.

SELECT​ ​SUM​(RESERVATION.Total) ​AS
Total_Sales,RENTAL_OFFICE_LOCATION.RentalOfficeID ​FROM​ RESERVATION
INNER​ ​JOIN​ RENTAL_OFFICE_LOCATION ​ON​ RESERVATION.RentalOfficeID =
RENTAL_OFFICE_LOCATION.RentalOfficeID ​GROUP​ ​BY​ RESERVATION.RentalOfficeID
ORDER​ ​BY​ ​SUM​(RESERVATION.Total) ​DESC​;

Total Reservations of Each Rental Office by Sales in Descending Order

mysql> ​SELECT​ ​SUM​(RESERVATION.Total) ​AS
Total_Sales,RENTAL_OFFICE_LOCATION.RentalOfficeID ​FROM​ RESERVATION
-> ​INNER​ ​JOIN​ RENTAL_OFFICE_LOCATION ​ON​ RESERVATION.RentalOfficeID =
RENTAL_OFFICE_LOCATION.RentalOfficeID ​GROUP​ ​BY​ RESERVATION.RentalOfficeID
ORDER​ ​BY​ ​SUM​(RESERVATION.Total) ​DESC​;
+​-------------+----------------+
| Total_Sales | RentalOfficeID |
+​-------------+----------------+
| 1450.00 | 3 |
| 1255.00 | 2 |
| 1120.00 | 4 |
| 285.00 | 1 |
+​-------------+----------------+
4 rows in ​set​ (​0.07​ sec)
Total Reservations of Each Rental Office by Sales in Descending Order

SELECT​ VEHICLE.Year, VEHICLE.Make, VEHICLE.Model, RESERVES.VIN,
SUM​(RESERVATION.Total) ​AS​ TOTAL
FROM​ ((VEHICLE
INNER​ ​JOIN​ RESERVES ​ON​ VEHICLE.VIN = RESERVES.VIN)
INNER​ ​JOIN​ RESERVATION ​ON​ RESERVES.ReservationID =
RESERVATION.ReservationID) ​GROUP​ ​BY​ VEHICLE.VIN ​ORDER​ B
​ Y
SUM​(RESERVATION.Total) ​DESC​;

Total Reservations of Each Rental Office by Sales in Descending Order Terminal Output

mysql> ​SELECT​ VEHICLE.Year, VEHICLE.Make, VEHICLE.Model, RESERVES.VIN,
SUM​(RESERVATION.Total) ​AS​ TOTAL
-> ​FROM​ ((VEHICLE
-> ​INNER​ ​JOIN​ RESERVES ​ON​ VEHICLE.VIN = RESERVES.VIN)
-> ​INNER​ ​JOIN​ RESERVATION ​ON​ RESERVES.ReservationID =
RESERVATION.ReservationID) ​GROUP​ ​BY​ VEHICLE.VIN ​ORDER​ B​ Y
SUM​(RESERVATION.Total) ​DESC​;
+​------+---------+----------+------------+---------+
| Year | Make | Model | VIN | TOTAL |
+​------+---------+----------+------------+---------+
| 2012 | Chevy | Tahoe | 33333CCCCC | 1500.00 |
| 2014 | Honda | Accord | 11111AAAAA | 875.00 |
| 2017 | Audi | A4 | 44444DDDDD | 875.00 |
| 2015 | Dodge | Charger | 55555EEEEE | 575.00 |
| 2016 | Hyundai | Veloster | 22222BBBBB | 285.00 |
+​------+---------+----------+------------+---------+
5 rows in ​set​ (​0.06​ sec)
Employee Information Grouped by Last Name

-- 1.) This query will pull employee information, and group the results by
their last name.

SELECT​ EmployeeID, EmployeeLName, EmployeeFName
FROM​ EMPLOYEE
GROUP​ ​BY​ EmployeeLName;

Employee Information Grouped by Last Name Terminal Output

mysql> ​SELECT​ EmployeeID, EmployeeLName, EmployeeFName
-> ​FROM​ EMPLOYEE
-> ​GROUP​ ​BY​ EmployeeLName;
+​------------+---------------+---------------+
| EmployeeID | EmployeeLName | EmployeeFName |
+​------------+---------------+---------------+
| 2 | Curry | Arthur |
| 3 | Danvers | Kara |
| 5 | Gordon | Barbara |
| 4 | Isley | Pamela |
| 7 | Jones | John |
| 10 | Kent | Clark |
| 11 | Luthor | Lex |
| 12 | Nygma | Edward |
| 8 | Queen | Oliver |
| 6 | Quinzel | Harleen |
| 1 | Stone | Victor |
| 9 | Wayne | Bruce |
+​------------+---------------+---------------+
12 rows in ​set​ (​0.06​ sec)
Total Cost of Reservation by Customer ID and Rental Vehicle VIN#

-- 2.) This query will pull vehicle and customer identification information
from existing reservations, and display them in order based on the total
cost of the reservation.

SELECT​ VIN, CustomerID, Total
FROM​ RESERVES, RESERVATION
WHERE​ RESERVES.ReservationID=RESERVATION.ReservationID
ORDER​ ​BY​ Total;

Total Cost of Reservation by Customer ID and Rental Vehicle VIN# Terminal Output

mysql> ​SELECT​ VIN, CustomerID, Total
-> ​FROM​ RESERVES, RESERVATION
-> ​WHERE​ RESERVES.ReservationID=RESERVATION.ReservationID
-> ​ORDER​ ​BY​ Total;
+​------------+------------+---------+
| VIN | CustomerID | Total |
+​------------+------------+---------+
| 22222BBBBB | 2 | 285.00 |
| 33333CCCCC | 6 | 380.00 |
| 55555EEEEE | 5 | 575.00 |
| 11111AAAAA | 1 | 875.00 |
| 44444DDDDD | 4 | 875.00 |
| 33333CCCCC | 3 | 1120.00 |
+​------------+------------+---------+
6 rows in ​set​ (​0.06​ sec)
Maintenance Log Ordered by Date

-- 3.) This query will pull all rows from the maintenance log, and will
order them by date from most recent to oldest.
SELECT​ *
FROM​ MAINTENANCE_LOG
ORDER​ ​BY​ Maintenance_Date;

Maintenance Log Ordered by Date Terminal Output

mysql> ​SELECT​ *
-> ​FROM​ MAINTENANCE_LOG
-> ​ORDER​ ​BY​ Maintenance_Date;
+​----------------+------------+------------+------------------+------------
-----------+
| Maintenance_ID | EmployeeID | VIN | Maintenance_Date |
Maintenance_Procedure |
+​----------------+------------+------------+------------------+------------
-----------+
| 1 | 9 | 11111AAAAA | 2016-05-08 ​ hange
| Oil C
|
| ​2​ | ​10​ | ​22222​BBBBB | ​2016-07-27​ | Tire
Replacement |
| ​3​ | ​11​ | ​33333​CCCCC | ​2016-11-27​ | Annual
Maintenance |
| ​4​ | ​12​ | ​44444​DDDDD | ​2017-02-08​ | Alignment
Check​ |
+​----------------+------------+------------+------------------+------------
-----------+
4​ ​rows​ ​in​ ​set​ (​0.06​ sec)
Reservation Date and Cost According to Rental Office Location

-- 4.) This query will pull reservation date and cost information, and will
display it organized by office location.

SELECT​ RentalOfficeID, Pick_Up_Date, Return_Date, Daily_Rate, Total
FROM​ RESERVATION
GROUP​ ​BY​ RentalOfficeID;

Reservation Date and Cost According to Rental Office Location Terminal Output

mysql> ​SELECT​ RentalOfficeID, Pick_Up_Date, Return_Date, Daily_Rate, Total
-> ​FROM​ RESERVATION
-> ​GROUP​ ​BY​ RentalOfficeID;
+​----------------+--------------+-------------+------------+---------+
| RentalOfficeID | Pick_Up_Date | Return_Date | Daily_Rate | Total |
+​----------------+--------------+-------------+------------+---------+
| 1 | 2017-03-01 | 2017-03-03 | 95.00 | 285.00 |
| 2 | 2017-06-06 | 2017-06-13 | 125.00 | 875.00 |
| 3 | 2017-06-06 | 2017-06-13 | 125.00 | 875.00 |
| 4 | 2017-04-05 | 2017-04-19 | 80.00 | 1120.00 |
+​----------------+--------------+-------------+------------+---------+
4 rows in ​set​ (​0.06​ sec)
Cost of Each Accessory According to Descending Order

-- 5.) This query will list each accessory type and its related cost, and
will organize the data in descending order by said cost.

Select​ ​Type​, ​Cost
FROM​ ACCESSORY
ORDER​ ​BY​ ​Cost​ ​DESC​;

Cost of Each Accessory According to Descending Order Terminal Output

mysql> ​Select​ ​Type​, ​Cost
-> ​FROM​ ACCESSORY
-> ​ORDER​ ​BY​ ​Cost​ ​DESC​;
+​----------------+-------+
| Type | Cost |
+​----------------+-------+
| Power Inverter | 50.00 |
| GPS | 25.00 |
| GPS | 25.00 |
| Phone Charger | 10.00 |
| Phone Charger | 10.00 |
+​----------------+-------+
5 rows in ​set​ (​0.07​ sec
Report Displaying Customer, Reservation and Vehicle Information

/*Report showing Customer Information, Reservation Information, and Vehicle
Information */

SELECT​ RESERVATION.ReservationID,CUSTOMER.CustomerFName ​AS​ FirstName,
CUSTOMER.CustomerLName ​AS​ LastName,
CUSTOMER_PHONE_NO.CustomerPhoneNo ​AS​ PhoneNumber,
RESERVATION.Pick_Up_Date, RESERVATION.Total ​as​ RentalPrice,
RENTAL_OFFICE_LOCATION.RentalOfficeID ​AS​ RentalLocation,
VEHICLE.VIN ​AS​ VehicleInfo
FROM​ CUSTOMER, RESERVATION, CUSTOMER_PHONE_NO, RENTAL_OFFICE_LOCATION,
VEHICLE, RESERVES
WHERE​ CUSTOMER.CustomerID = RESERVATION.CustomerID ​AND
CUSTOMER_PHONE_NO.CustomerID = CUSTOMER.CustomerID ​AND
RENTAL_OFFICE_LOCATION.RentalOfficeID = RESERVATION.RentalOfficeID
AND
VEHICLE.VIN = RESERVES.VIN ​AND
RESERVATION.ReservationID = RESERVES.ReservationID
ORDER​ ​BY​ ReservationID;

Report Displaying Customer, Reservation and Vehicle Information Terminal Output

mysql> ​SELECT​ RESERVATION.ReservationID,CUSTOMER.CustomerFName ​AS
FirstName, CUSTOMER.CustomerLName ​AS​ LastName,
-> CUSTOMER_PHONE_NO.CustomerPhoneNo ​AS​ PhoneNumber,
RESERVATION.Pick_Up_Date, RESERVATION.Total ​as​ RentalPrice,
-> RENTAL_OFFICE_LOCATION.RentalOfficeID ​AS​ RentalLocation,
VEHICLE.VIN ​AS​ VehicleInfo
-> ​FROM​ CUSTOMER, RESERVATION, CUSTOMER_PHONE_NO,
RENTAL_OFFICE_LOCATION, VEHICLE, RESERVES
-> ​WHERE​ CUSTOMER.CustomerID = RESERVATION.CustomerID ​AND
-> CUSTOMER_PHONE_NO.CustomerID = CUSTOMER.CustomerID ​AND
-> RENTAL_OFFICE_LOCATION.RentalOfficeID =
RESERVATION.RentalOfficeID ​AND
-> VEHICLE.VIN = RESERVES.VIN ​AND
-> RESERVATION.ReservationID = RESERVES.ReservationID
-> ​ORDER​ ​BY​ ReservationID;
+​---------------+-----------+-------------+---------------+--------------+-
------------+----------------+-------------+
| ReservationID | FirstName | LastName | PhoneNumber | Pick_Up_Date |
RentalPrice | RentalLocation | VehicleInfo |
+​---------------+-----------+-------------+---------------+--------------+-
------------+----------------+-------------+
| 1 | John | Constantine | (555)555-1313 | 2017-06-06 |
875.00 | 3 | 11111AAAAA |
| 1 | John | Constantine | (555)555-1919 | 2017-06-06 |
875.00 | 3 | 11111AAAAA |
| 2 | Hal | Jordan | (555)555-0101 | 2017-03-01 |
285.00 | 1 | 22222BBBBB |
| 2 | Hal | Jordan | (555)555-9999 | 2017-03-01 |
285.00 | 1 | 22222BBBBB |
| 3 | Barry | Allen | (555)555-0001 | 2017-04-05 |
1120.00 | 4 | 33333CCCCC |
| 4 | Dinah | Lance | (555)555-8888 | 2017-06-06 |
875.00 | 2 | 44444DDDDD |
| 5 | Felicity | Smoak | (555)555-1612 | 2017-07-22 |
575.00 | 3 | 55555EEEEE |
| 6 | Zatanna | Zatara | (555)555-6666 | 2017-08-19 |
380.00 | 2 | 33333CCCCC |
+​---------------+-----------+-------------+---------------+--------------+-
------------+----------------+-------------+
8 rows in ​set​ (​0.06​ sec)
Prices of Reservations with the Accessory Cost Added

/* Show prices of reservations with the accessory cost added */

SELECT​ RESERVATION.ReservationID, (RESERVATION.Total + ACCESSORY.Cost) ​AS
TotalCost, CustomerLName ​AS​ LastName
FROM​ RESERVATION, INCLUDES, ACCESSORY, CUSTOMER
WHERE​ RESERVATION.ReservationID = INCLUDES.ReservationID ​AND
INCLUDES.SerialNumber = ACCESSORY.SerialNumber ​AND
CUSTOMER.CustomerID = RESERVATION.CustomerID
ORDER​ ​BY​ RESERVATION.ReservationID;

Prices of Reservations with the Accessory Cost Added Terminal Output

mysql> ​SELECT​ RESERVATION.ReservationID, (RESERVATION.Total +
ACCESSORY.Cost) ​AS​ TotalCost, CustomerLName ​AS​ LastName
-> ​FROM​ RESERVATION, INCLUDES, ACCESSORY, CUSTOMER
-> ​WHERE​ RESERVATION.ReservationID = INCLUDES.ReservationID ​AND
-> INCLUDES.SerialNumber = ACCESSORY.SerialNumber ​AND
-> CUSTOMER.CustomerID = RESERVATION.CustomerID
-> ​ORDER​ ​BY​ RESERVATION.ReservationID;
+​---------------+-----------+-------------+
| ReservationID | TotalCost | LastName |
+​---------------+-----------+-------------+
| 1 | 900.00 | Constantine |
| 2 | 310.00 | Jordan |
| 3 | 1130.00 | Allen |
| 4 | 925.00 | Lance |
+​---------------+-----------+-------------+
4 rows in ​set​ (​0.08​ sec)
Vehicle Age with Model and Make

/*Vehicle Age with model and make*/

SELECT​ VEHICLE.LicensePlate, VEHICLE.Make, VEHICLE.Model,
(​YEAR​(RESERVATION.Pick_Up_Date) - VEHICLE.Year) ​AS​ VehicleAge
FROM​ VEHICLE, RESERVES, RESERVATION
WHERE​ RESERVATION.ReservationID = RESERVES.ReservationID ​AND
VEHICLE.VIN = RESERVES.VIN;

Vehicle Age with Model and Make Terminal Output

mysql> ​SELECT​ VEHICLE.LicensePlate, VEHICLE.Make, VEHICLE.Model,
(​YEAR​(RESERVATION.Pick_Up_Date) - VEHICLE.Year) ​AS​ VehicleAge
-> ​FROM​ VEHICLE, RESERVES, RESERVATION
-> ​WHERE​ RESERVATION.ReservationID = RESERVES.ReservationID ​AND
-> VEHICLE.VIN = RESERVES.VIN;
+​--------------+---------+----------+------------+
| LicensePlate | Make | Model | VehicleAge |
+​--------------+---------+----------+------------+
| AA11BB22 | Honda | Accord | 3 |
| BB22CC33 | Hyundai | Veloster | 1 |
| CC33DD44 | Chevy | Tahoe | 5 |
| CC33DD44 | Chevy | Tahoe | 5 |
| DD44EE55 | Audi | A4 | 0 |
| EE55FF66 | Dodge | Charger | 2 |
+​--------------+---------+----------+------------+
6 rows in ​set​ (​0.06​ sec)
Employee Count by Rental Office

/* Employee count by rental office */

SELECT​ RENTAL_OFFICE_LOCATION.RentalOfficeID, RENTAL_OFFICE_LOCATION.City
AS​ Location, ​COUNT​(EMPLOYEE.EmployeeID) ​AS​ EmployeeCount
FROM​ RENTAL_OFFICE_LOCATION, EMPLOYEE, EMPLOYING
WHERE​ RENTAL_OFFICE_LOCATION.RentalOfficeID = EMPLOYING.RentalOfficeID ​AND
EMPLOYING.EmployeeID = EMPLOYEE.EmployeeID
GROUP​ ​BY​ RENTAL_OFFICE_LOCATION.RentalOfficeID;

Employee Count by Rental Office Terminal Output

mysql> ​SELECT​ RENTAL_OFFICE_LOCATION.RentalOfficeID,
RENTAL_OFFICE_LOCATION.City ​AS​ Location, ​COUNT​(EMPLOYEE.EmployeeID) ​AS
EmployeeCount
-> ​FROM​ RENTAL_OFFICE_LOCATION, EMPLOYEE, EMPLOYING
-> ​WHERE​ RENTAL_OFFICE_LOCATION.RentalOfficeID =
EMPLOYING.RentalOfficeID ​AND
-> EMPLOYING.EmployeeID = EMPLOYEE.EmployeeID
-> ​GROUP​ ​BY​ RENTAL_OFFICE_LOCATION.RentalOfficeID;
+​----------------+------------+---------------+
| RentalOfficeID | Location | EmployeeCount |
+​----------------+------------+---------------+
| 1 | Portland | 3 |
| 2 | Gilead | 3 |
| 3 | Estes Park | 3 |
| 4 | Derry | 3 |
+​----------------+------------+---------------+
4 rows in ​set​ (​0.06​ sec)
Show Vehicles with Maintenance Records

/*Show vehicles with maintenance record*/

SELECT​ MAINTENANCE_LOG.Maintenance_ID, MAINTENANCE_LOG.Maintenance_Date,
MAINTENANCE_LOG.Maintenance_Procedure,
VEHICLE.LicensePlate, VEHICLE.Model, EMPLOYEE.EmployeeID,
EMPLOYEE.EmployeeLName ​AS​ LastName
FROM​ MAINTENANCE_LOG, VEHICLE, EMPLOYEE
WHERE​ MAINTENANCE_LOG.EmployeeID = EMPLOYEE.EmployeeID ​AND
MAINTENANCE_LOG.VIN = VEHICLE.VIN;

Show Vehicles with Maintenance Records Terminal Output

mysql> ​SELECT​ MAINTENANCE_LOG.Maintenance_ID,
MAINTENANCE_LOG.Maintenance_Date, MAINTENANCE_LOG.Maintenance_Procedure,
-> VEHICLE.LicensePlate, VEHICLE.Model, EMPLOYEE.EmployeeID,
EMPLOYEE.EmployeeLName ​AS​ LastName
-> ​FROM​ MAINTENANCE_LOG, VEHICLE, EMPLOYEE
-> ​WHERE​ MAINTENANCE_LOG.EmployeeID = EMPLOYEE.EmployeeID ​AND
-> MAINTENANCE_LOG.VIN = VEHICLE.VIN;
+​----------------+------------------+-----------------------+--------------
+----------+------------+----------+
| Maintenance_ID | Maintenance_Date | Maintenance_Procedure | LicensePlate
| Model | EmployeeID | LastName |
+​----------------+------------------+-----------------------+--------------
+----------+------------+----------+
| 1 | 2016-05-08 | Oil ​Change​ | AA11BB22
| Accord | ​9​ | Wayne |
| ​2​ | ​2016-07-27​ | Tire Replacement | BB22CC33
| Veloster | ​10​ | Kent |
| ​3​ | ​2016-11-27​ | Annual Maintenance | CC33DD44
| Tahoe | ​11​ | Luthor |
| ​4​ | ​2017-02-08​ | Alignment ​Check​ | DD44EE55
| A4 | ​12​ | Nygma |
+​----------------+------------------+-----------------------+--------------
+----------+------------+----------+
4​ ​rows​ ​in​ ​set​ (​0.06​ sec)
Reservation Count by Office Location

/*Reservation Count by Office Location*/

​SELECT
RESERVATION.RentalOfficeID,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATI
ON.State,​COUNT​(RESERVATION.RESERVATIONID) ​AS​ RESERVATIONCOUNT
​FROM​ RESERVATION,RENTAL_OFFICE_LOCATION,RESERVES
​WHERE​ RESERVATION.RentalOfficeID = RENTAL_OFFICE_LOCATION.RentalOfficeID
​AND​ RESERVATION.ReservationID = RESERVES.ReservationID
​GROUP​ ​BY​ RENTAL_OFFICE_LOCATION.RentalOfficeID;

Reservation Count by Office Location Terminal Output

mysql> ​SELECT
RESERVATION.RentalOfficeID,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATI
ON.State,​COUNT​(RESERVATION.RESERVATIONID) ​AS​ RESERVATIONCOUNT
-> ​FROM​ RESERVATION,RENTAL_OFFICE_LOCATION,RESERVES
-> ​WHERE​ RESERVATION.RentalOfficeID =
RENTAL_OFFICE_LOCATION.RentalOfficeID
-> ​AND​ RESERVATION.ReservationID = RESERVES.ReservationID
-> ​GROUP​ ​BY​ RENTAL_OFFICE_LOCATION.RentalOfficeID;
+​----------------+------------+-------+------------------+
| RentalOfficeID | City | State | RESERVATIONCOUNT |
+​----------------+------------+-------+------------------+
| 1 | Portland | OR | 1 |
| 2 | Gilead | NY | 2 |
| 3 | Estes Park | CO | 2 |
| 4 | Derry | ME | 1 |
+​----------------+------------+-------+------------------+
4 rows in ​set​ (​0.07​ sec)
Customer Accessory Selection

/*Customer Accessory Selection*/

Select​ RESERVATION.ReservationID,CUSTOMER.CustomerID,CUSTOMER.CustomerFName
AS​ FirstName,CUSTOMER.CustomerLName ​AS
LastName,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATION.State,ACCESSORY
.Type,ACCESSORY.QUANTITY
FROM​ RESERVATION, INCLUDES, ACCESSORY, CUSTOMER, RENTAL_OFFICE_LOCATION
WHERE​ RESERVATION.ReservationID = INCLUDES.ReservationID ​AND
INCLUDES.SerialNumber = ACCESSORY.SerialNumber ​AND
CUSTOMER.CustomerID = RESERVATION.CustomerID ​AND
RESERVATION.RentalOfficeID = RENTAL_OFFICE_LOCATION.RentalOfficeID
ORDER​ ​BY​ CUSTOMER.CustomerLName;

Customer Accessory Selection Terminal Output

mysql> ​Select
RESERVATION.ReservationID,CUSTOMER.CustomerID,CUSTOMER.CustomerFName ​AS
FirstName,CUSTOMER.CustomerLName ​AS
LastName,RENTAL_OFFICE_LOCATION.City,RENTAL_OFFICE_LOCATION.State,ACCESSORY
.Type,ACCESSORY.QUANTITY
-> ​FROM​ RESERVATION, INCLUDES, ACCESSORY, CUSTOMER,
RENTAL_OFFICE_LOCATION
-> ​WHERE​ RESERVATION.ReservationID = INCLUDES.ReservationID ​AND
-> INCLUDES.SerialNumber = ACCESSORY.SerialNumber ​AND
-> CUSTOMER.CustomerID = RESERVATION.CustomerID ​AND
-> RESERVATION.RentalOfficeID = RENTAL_OFFICE_LOCATION.RentalOfficeID
-> ​ORDER​ ​BY​ CUSTOMER.CustomerLName;
+​---------------+------------+-----------+-------------+------------+------
-+----------------+----------+
| ReservationID | CustomerID | FirstName | LastName | City | State
| Type | QUANTITY |
+​---------------+------------+-----------+-------------+------------+------
-+----------------+----------+
| 3 | 3 | Barry | Allen | Derry | ME
| Phone Charger | 1 |
| 1 | 1 | John | Constantine | Estes Park | CO
| GPS | 1 |
| 2 | 2 | Hal | Jordan | Portland | OR
| GPS | 1 |
| 4 | 4 | Dinah | Lance | Gilead | NY
| Power Inverter | 1 |
+​---------------+------------+-----------+-------------+------------+------
-+----------------+----------+
4 rows in ​set​ (​0.07​ sec)
Number of Rental Days
/*Number of Rental Days*/

SELECT
RESERVATION.ReservationID,VEHICLE.VIN,VEHICLE.MAKE,VEHICLE.MODEL,​DATEDIFF​(R
ESERVATION.Pick_Up_Date,RESERVATION.Return_Date) ​AS​ NumOfRentalDays
FROM​ RESERVATION,VEHICLE,RESERVES
WHERE​ RESERVATION.ReservationID = RESERVES.ReservationID
​AND​ RESERVES.VIN = VEHICLE.VIN;

Number of Rental Days Terminal Output

mysql> ​SELECT
RESERVATION.ReservationID,VEHICLE.VIN,VEHICLE.MAKE,VEHICLE.MODEL,​DATEDIFF​(R
ESERVATION.Pick_Up_Date,RESERVATION.Return_Date) ​AS​ NumOfRentalDays
-> ​FROM​ RESERVATION,VEHICLE,RESERVES
-> ​WHERE​ RESERVATION.ReservationID = RESERVES.ReservationID
-> ​AND​ RESERVES.VIN = VEHICLE.VIN;
+​---------------+------------+---------+----------+-----------------+
| ReservationID | VIN | MAKE | MODEL | NumOfRentalDays |
+​---------------+------------+---------+----------+-----------------+
| 1 | 11111AAAAA | Honda | Accord | -7 |
| 2 | 22222BBBBB | Hyundai | Veloster | -2 |
| 3 | 33333CCCCC | Chevy | Tahoe | -14 |
| 6 | 33333CCCCC | Chevy | Tahoe | -4 |
| 4 | 44444DDDDD | Audi | A4 | -7 |
| 5 | 55555EEEEE | Dodge | Charger | -5 |
+​---------------+------------+---------+----------+-----------------+
6 rows in ​set​ (​0.06​ sec)