Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the table TRUCK with attributes TruckID, TruckModel, Miles, and Gallons, and the table LIMITS with attribute HighMPGLimit, defined and populated by the following script:
Consider the table TRUCK with attributes TruckID, TruckModel, Miles, and Gallons, and the table LIMITS with attribute HighMPGLimit, defined and populated by the following script:
DROP TABLE TRUCK CASCADE CONSTRAINTS;
CREATE TABLE TRUCK
TruckID INTEGER PRIMARY KEY,
TruckModel CHAR
Miles NUMBER
Gallons NUMBER
;
INSERT INTO TRUCK VALUES 'Silverado', ;
INSERT INTO TRUCK VALUES 'Sierra ;
INSERT INTO TRUCK VALUES 'Silverado', ;
INSERT INTO TRUCK VALUES 'Sierra ;
INSERT INTO TRUCK VALUES F;
INSERT INTO TRUCK VALUES 'Titan XD;
INSERT INTO TRUCK VALUES 'Ram ;
SELECT FROM TRUCK;
DROP TABLE LIMITS CASCADE CONSTRAINTS;
CREATE TABLE LIMITS
HighMPGLimit NUMBER
;
INSERT INTO LIMITS VALUES ;
SELECT FROM LIMITS;
COMMIT;
Write a script file Assignmentsql containing just an anonymous PLSQL block that will do the following:
First, read the high milespergallon MPG limit from the LIMITS table, store it in a variable, and display its value. You may assume that the LIMITS table contains exactly one record.
Next, for each truck in the TRUCK table, compute the milespergallon for the truck number of miles for the truck divided by the number of gallons used, rounded to two decimal places Output each trucks information on a single line, showing the ID model, and milespergallon for the truck. Add the word HIGH to the end of each line in which the milespergallon is greater than or equal to the high milespergallon limit
Also compute the overall milespergallon for all of the trucks together total miles driven by all trucks divided by total gallons used by all trucks, rounded to two decimal places and the number of trucks that reached or exceeded the high milespergallon limit and report those values at the end.
For the sample data given, the output should be:
High MPG limit:
Truck : Silverado
Truck : Sierra HIGH
Truck : Silverado
Truck : Sierra HIGH
Truck : F
Truck : Titan XD HIGH
Truck : Ram HIGH
Overall fleet MPG:
Trucks with high MPG:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started