Sie sind auf Seite 1von 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. Ourmissionistosatisfyourcustomersrentalcarneedswhiledelivering
thebestquality,serviceandvalue;webelievetheidealsystemisa
human-centereduser-experiencemodeledaccordingtoaconsistent
object-orientedmodelfromthefront-endallthewaytotheback-endof
thedatabase.1Concordantly,webelieveboththeentityrelationship
diagramandrelationaldatabase-modelspecificationsrequiredbythe
rental-carmanagementinventorysystemwillseekto:
i. Proactivelymaintainandmonitorthedatabasesystemtoprevent
anypotentialissues.2
ii. Accuratelydiagnoseandforecastthedatabasesystemhealthand
capacitytomaximizereturnoninvestmentfortherental-car
inventorymanagementsystemandpromptlyrespondtothe
stakeholderssupportrequest(s)toremoveanyworkbottleneckon
DBAside.3
iii. PersistentlyseekinnovativewaystoimproveDBAworkefficiently
yeteffectively.4
2. Mission Objectives
a. Checkvehicleinventorybylocation
b. Associatecustomerinformationwithrentalcarreservation
c. Trackrentalcarinventory
d. Trackrentalcarmaintenance
e. Trackaccessoryinventory
3. Requirements
a. Arentalcarcompanywantstomonitorvehicle-inventoryand
reservations.
b. Foreachvehicle,wewillrecordMake,Model,Year,Color,LicensePlate,
MileageandVIN.
c. Foreachcustomer,weassignaunique-identifier(ID),FirstName,
LastName,PhoneNumber,EmailAddress,DriversLicense,and
RewardsNumber.
d. Foreachrental-officelocation,wewillassignuniqueidentifier(ID)for
RentalOfficeID,StreetAddress,City,StateandZipCode.

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. Everytimeacustomerreservesacar,thereservationwillbeassigneda
unique-identifier(ID),Pick-upDate,ReturnDate,DailyRate,Total,
CustomerIDandRentalOfficeID.
f. Acustomercanreservemanycars,butmusthaveatleastonerental
reservation.
g. Acarmaybereservedbymanycustomers,ornoneatall.
h. Amaintenance-logwillrecordVehicleID,Procedure,Date.
i. Therental-companywillofferaccessoriesforeachcustomer-reservation.
Foreachaccessory,wewillmaintainaunique-identifiercalled
SerialNumber,type,cost,andquantitywhichwillcorrespondto
RentalOfficeID,CustomerID,VehicleIDandReservationID.
j. ARentalOfficeLocationcanhavemanyvehicles,butmusthaveatleast
one.
k. AVehiclemaybeusedbymultipleRentalOfficeLocations,butmusthave
atleastone.
l. AVehiclemayhavemanyreservations,ornoneatall.
m. ARentalOfficeLocationcanhavemanyemployees,butmusthaveat
leastone.
n. AnEmployeecanworkatmultipleRentalOfficeLocations,butmustwork
atatleastone.
o. ARentalOfficeLocationcanhavemultipleReservations,andmayhave
none.
p. AReservationmusthaveoneRentalOfficeLocation.
q. AReservationmusthaveonevehicle.
r. AReservationmayhaveoneormoreaccessories,butmayhavenone.
s. AnAccessorycanbeusedinmultipleReservations,ornoneatall.
t. MaintenancemustbecompletedbyatleastoneEmployee,butcanbe
completedbymultipleemployees
u. Theattributevehicleageiscalculatedbysubtractingvehiclemodelyear
fromthedateofreservation.
4. Entity Relationship Diagram (ERD)
a. AnEmployeemayperformmultiplemaintenanceactivities,ortheymay
notperformany.
b. ARentalOfficeLocationmayhavemultiplecustomers,ornoneatall
c. ACustomermayusemultipleRentalOfficeLocations,butmustuseat
leastone(fiveentitiesandatleastfourbinaryrelationships).Atleastone
oftherelationshipsshouldbemanytomany.Showallattributesofall
entities.
d. WeinvitereviewoftheERDmodeledat[LucidCharts](link).
e. Attribute Modeling
i. Bold-ForeignKey
ii. Underline-PotentialPrimaryKey
iii. Tables
1. Accessory (GPS, etc.)
a. SerialNumber
b. Type
c. Cost
d. Quantity
2. Customer
a. CustomerID
b. CustomerFName
c. CustomerLName
d. CustomerEmail
e. DriversLicenseNumber(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. MaintenanceLog
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. DailyRate
d. Total
e. CustomerID(FK)
f. RentalOfficeID(FK)
11. Vehicle
a. VIN
b. Make
c. Model
d. Year
e. Color
f. LicensePlate(U)
g. Mileage

Post-Mortem

Ourinitialmodelsincludedtworelationsthathadidenticalnames:Reserves.
Thiswasasimpleoversightthatmerelyrequiredustoalterthenameofthe
relationbetweenAccessoryandReservationtoIncludes.
OurinitialdesigncalledforaternaryrelationshipbetweenVehicle,Accessory,
andReservationtables.However,afterdiscussionwedecidedtodividethe
singlerelationoutintotwoseparaterelations,onebetweenVehicleand
Reservationtables,andonebetweenAccessoryandReservationtables.Our
logicbehindthisdecisionisthatitisfullypossibleforareservationtonothave
anyaccessoriesattachedtoit,andbyautomaticallyincludingacolumnforthe
accessoryserialnumberintherelationtablecouldresultinasignificantamount
ofnullvaluesforthatcolumn,whichwouldhaveservedasaforeignkey.In
dividingthetworelationsintoseparatetables,wewereabletoensurethatthere
wouldbenonullforeignkeyvalues.
Theinitialdesignonlyallowedforasinglephonenumbertobeassignedtoeach
customer.However,afterdiscussionitwasdecidedthatthiswouldnotbe
sufficient,asmultiplecontactnumbersarecommon.Tosolveforthis,weadded
anadditionaltablethatislinkedtotheCustomertable,usingCustomerIDasa
foreignkeytoincorporatemultiplephonenumbers.Ourinitialimplementationof
thistablewasincorrectthough,astherewasnoprimarykeyassignedtothe
table.AftertestingtheinitialtableCREATEanddataINSERTstatements,we
discoveredourerrorandestablishedthephonenumbercolumnastheprimary
keycolumn.
Atthestart,wehadmisstatedtherequirementsnecessaryforhowtracking
vehiclemaintenancewouldwork.Wehadincorrectlyassumedaonetomany
relationshipbetweenthevehicleandtheemployee,thusoverlookingtheneed
forarelationaltablethatlinkedthesetwoentities.Oncetherequirementshad
beencorrected,wealsodesignedtheMaintenance_Logtable,thatwouldstore
thenecessary,andrelevantdata,fortrackingmaintenanceupdatesperformed
onthevehiclesinquestion.
OurupdateddesigncalledforacolumnlabelledProcedureinthe
Maintenance_LogTable.Duringourdesignphasethough,wedidnotrealize
thatProcedureisareservedterminSQL,anditwouldnotbepossibleforus
tousethistitleforthecolumn.AftertroubleshootingourCREATEstatement,we
discoveredtheerror,andhadtobacktrackandupdateourdesigntore-name
thiscolumnMaintenance_Procedure.
Ourupdateddesignwasalsolackinganothercriticalpieceofdatainregardsto
theMaintenance_Logtable:theprimarykey.Afterexperiencingsomeissuesin
creatingandpopulatingthetable,werealizedthateachindividualprocedure
wouldneedsitsownuniqueidentifier,andaddedintheMaintenance_ID
column.
IndefiningtherequirementsforourReservationtable,wehadspecifiedthe
needtostoredatathatwouldallowforthecalculationoftotalcostofthe
reservation,anddecidedtodosobytrackingthedatesoftherentalandthe
dailycost.However,inourinitialdesign,thetableonlyhadasinglecolumnfor
reservationdates.Storingthisdatainasinglecolumnwouldnothaveallowed
ustoeasilytrackthetotalnumberofdaysthatthereservationspanned,sowe
hadtoupdatethedatabasetoholdanadditionalcolumn,thusallowingusto
splitthedatesintoaPick_Up_DatecolumnandaReturn_datecolumn.

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 | 22222BBBBB | 2016-07-27 | Tire
Replacement |
| 3 | 11 | 33333CCCCC | 2016-11-27 | Annual
Maintenance |
| 4 | 12 | 44444DDDDD | 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)

Das könnte Ihnen auch gefallen