car maintenance example solution. tables...
TRANSCRIPT
![Page 1: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/1.jpg)
Car Maintenance ExampleSolution
![Page 2: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/2.jpg)
TablesREGISTRATION
CAR_MAKE
CAR_MODEL
CAR_COLOUR MODEL_YEAR
LINCENCE_NO
3679MR82 Toyota Corolla Blue 2006 1967fr89768
E-TS865 Nissan Micro Red 2004 1973Smith121
PE57UVP Peugeot 407 Blue 2007 1990byt3212
PISE567 Volkswagen
Eos Lime 2006 DF-678-WV
ROMA482 Volkswagen
Golf GT Black 2007 AQ-123-AV
Z-BA975 Peugeot 207 Black 2007 1980vrt7312PART_NO PART_NAME PART_COST12390 Paint
sealantsGhȻ14.95
12391 Wiper GhȻ19.9512392 Brake pads GhȻ24.9912393 Brake Discs GhȻ49.5412395 Spark Plugs GhȻ0.9912396 Airbag GhȻ24.9512397 Tyres GhȻ25.00
CAR
PART
![Page 3: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/3.jpg)
Tables(cont’d)
INSPECTION_CODE REGISTRATION INSPECTION_DATE EVALUATION
100036 PE57UVP 10/05/2008 FAIL100390 ROMA482 01/09/2008 106750 E-TS865 01/03/2006 PASS122456 Z-BA975 03/10/2008 FAIL145678 PISE567 30/09/2007 PASS200450 E-TS865 21/02/2005 PASS200456 E-TS865 01/04/2007 FAIL
MAINTENANCE_RECORD
INSPECTION_CODE PART_NO106750 12396106750 12397100036 12393200450 12391100036 12397200450 12392200456 12397
REPAIR
![Page 4: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/4.jpg)
Questions
1. Display all the part names and their
prices where the cost of the part is
greater than GhȻ20.00
2. List the car registration and model
details and part numbers for all cars
where the model year is 2007, where an
inspection was carried out after
01/03/2008, which resulted in a part
being required for the repair.
![Page 5: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/5.jpg)
Question 1: Solution
PART_NAME PART_COST
Brake pads
GhȻ24.99
Brake Discs
GhȻ49.54
Airbag GhȻ24.95
Tyres GhȻ25.00
Π𝑝𝑎𝑟𝑡𝑛𝑎𝑚𝑒¿
![Page 6: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/6.jpg)
Question 2: Solution
STEP1:•The first part of the query states that we
need the attributes REGISTRATION and CAR_MODEL from the CAR relation.
•Further, we are only interested in cars whose MODEL_YEAR is 2007
![Page 7: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/7.jpg)
Question 2: Solution
STEP1:
REGISTRATION
CAR_MODEL
PE57UVP 407
ROMA482 Golf GT
Z-BA975 207
Π 𝑟𝑒𝑔𝑖𝑠𝑡𝑟𝑎𝑡𝑖𝑜𝑛 ,𝑐𝑎𝑟𝑚𝑜𝑑𝑒𝑙(𝜎𝑚𝑜𝑑𝑒𝑙 𝑦𝑒𝑎𝑟=2007
(𝐶𝐴𝑅))
![Page 8: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/8.jpg)
Question 2: Solution
STEP2:•Next, the query requires information about
inspections which were carried out after 01/03/2008. Information about inspections is stored in the MAINTENANCE_RECORD relation.
•Since the query is not asking for specific attributes, we assume that the values of all attributes in the MAINTENANCE_RECORD is required.
•Further, we must restrict the query to only tuples where the INSPECTION_DATE > 01/03/2008.
![Page 9: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/9.jpg)
Question 2: Solution
STEP2:𝜎 𝑖𝑛𝑠𝑝𝑒𝑐𝑡𝑖𝑜𝑛𝑑𝑎𝑡𝑒>01/03/2008
(𝑀𝐴𝐼𝑁𝑇𝐸𝑁𝐴𝑁𝐶𝐸𝑅𝐸𝐶𝑂𝑅𝐷 )
INSPECTION_CODE
REGISTRATION
INSPECTION_DATE
EVALUATION
100036 PE57UVP 10/05/2008 FAIL
100390 ROMA482
01/09/2008
122456 Z-BA975 03/10/2008 FAIL
![Page 10: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/10.jpg)
Question 2: Solution
STEP3:•Next, perform a NATURAL JOIN on the
query results from STEPs 1 & 2 with the common column (REGISTRATION) in both the CAR and MAINTENANCE_RECORD relations.
•STEP3a:▫In performing the NATURAL JOIN first
perform the Cartesian Product on CAR and MAINTENANCE_RECORD relations. Prefix each attribute in the CAR and MAINTENANCE_RECORD relations with C and M respectively.
![Page 11: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/11.jpg)
Question 2: Solution
STEP3a:Cartesian Product: X CAR
M.INSPECTION_CODE
M.REGISTRATION
M.INSPECTION_DATE
M.EVALUATION
C.REGISTRATION
C.CAR_MODEL
100036 PE57UVP 10/05/2008 FAIL PE57UVP 407
100036 PE57UVP 10/05/2008 FAIL ROMA482 Golf GT
100036 PE57UVP 10/05/2008 FAIL Z-BA975 207
100390 ROMA482 01/09/2008 PE57UVP 407
100390 ROMA482 01/09/2008 ROMA482 Golf GT
100390 ROMA482 01/09/2008 Z-BA975 207
122456 Z-BA975 03/10/2008 FAIL PE57UVP 407
122456 Z-BA975 03/10/2008 FAIL ROMA482 Golf GT
122456 Z-BA975 03/10/2008 FAIL Z-BA975 207
![Page 12: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/12.jpg)
Question 2: SolutionSTEP3b:
SELECT only the rows for which the REGISTRATION values are equal
M.INSPECTION_CODE
M.REGISTRATION
M.INSPECTION_DATE
M.EVALUATION
C.REGISTRATION
C.CAR_MODEL
100036 PE57UVP
10/05/2008 FAIL PE57UVP 407
100390 ROMA482
01/09/2008 ROMA482 Golf GT
122456 Z-BA975 03/10/2008 FAIL Z-BA975 207
![Page 13: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/13.jpg)
Question 2: SolutionSTEP3c:
Perform a PROJECT on either C.REGISTRATION or M.REGISTRATION to the result in STEP3b
and drop the prefix’s C or M in the final relation.
INSPECTION_CODE REGISTRATION INSPECTION_DATE EVALUATION CAR_MODEL
100036 PE57UVP 10/05/2008 FAIL 407
100390 ROMA482 01/09/2008 Golf GT
122456 Z-BA975 03/10/2008 FAIL 207
![Page 14: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/14.jpg)
Question 2: Solution
STEP4:
•The query further requires that the
information be restricted for cars where a
part was needed for a repair. This
information can be found in the REPAIR
relation by looking for a PART_NO in the
REPAIR relation, which corresponds to a
specific INSPECTION_CODE in the
MAINTENANCE_RECORD relation.
![Page 15: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/15.jpg)
Question 2: SolutionSTEP4:Perform a NATURAL JOIN with the common
column (INSPECTION_CODE) in both the REPAIR and Query Result of STEP3c.
INSPECTION_CODE REGISTRATION INSPECTION_DATE
EVALUATION CAR_MODEL
PART_NO
100036 PE57UVP 10/05/2008 FAIL 407 12393
100036 PE57UVP 10/05/2008 FAIL 407 12397
QueryResult
![Page 16: Car Maintenance Example Solution. Tables REGISTRATIONCAR_MAKECAR_MODELCAR_COLOURMODEL_YEARLINCENCE_NO 3679MR82ToyotaCorollaBlue20061967fr89768 E-TS865NissanMicroRed20041973Smith121](https://reader035.vdocuments.net/reader035/viewer/2022072006/56649d205503460f949f5295/html5/thumbnails/16.jpg)
Question 2: SolutionSTEP5:
Finally, the original query requested that we list “the car registration, model details and part numbers.”This requires that we perform a PROJECT on the query result of STEP4.
REGISTRATION CAR_MODEL PART_NO
PE57UVP 407 12393
PE57UVP 407 12397
Π 𝑟𝑒𝑔𝑖𝑠𝑡𝑟𝑎𝑡𝑖𝑜𝑛 ,𝑐𝑎𝑟𝑚𝑜𝑑𝑒𝑙 ,𝑝𝑎𝑟𝑡𝑛𝑜(𝑄𝑢𝑒𝑟𝑦𝑅𝑒𝑠𝑢𝑙𝑡 )