Answered step by step
Verified Expert Solution
Link Copied!

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(16),
Miles NUMBER(7,1),
Gallons NUMBER(5,1)
);
INSERT INTO TRUCK VALUES (1, 'Silverado', 2651.0,135.0);
INSERT INTO TRUCK VALUES (2, 'Sierra 2500',1388.8,55.0);
INSERT INTO TRUCK VALUES (3, 'Silverado', 2301.1,160.4);
INSERT INTO TRUCK VALUES (4, 'Sierra 1000',2575.0,115.5);
INSERT INTO TRUCK VALUES (5,'F-150',2817.0,150.0);
INSERT INTO TRUCK VALUES (6, 'Titan XD',3698.5,165.6);
INSERT INTO TRUCK VALUES (7, 'Ram 1500',4434.8,185.7);
SELECT * FROM TRUCK;
DROP TABLE LIMITS CASCADE CONSTRAINTS;
CREATE TABLE LIMITS
(
HighMPGLimit NUMBER(2,0)
);
INSERT INTO LIMITS VALUES (22);
SELECT * FROM LIMITS;
COMMIT;
Write a script file Assignment6.sql containing just an anonymous PL/SQL block that will do the following:
First, read the high miles-per-gallon (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 miles-per-gallon 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 miles-per-gallon for the truck. Add the word HIGH to the end of each line in which the miles-per-gallon is greater than or equal to the high miles-per-gallon limit.
Also compute the overall miles-per-gallon 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 miles-per-gallon limit, and report those values at the end.
For the sample data given, the output should be:
High MPG limit: 22
Truck 1: Silverado 19.64
Truck 2: Sierra 250025.25 HIGH
Truck 3: Silverado 14.35
Truck 4: Sierra 100022.29 HIGH
Truck 5: F-15018.78
Truck 6: Titan XD 22.33 HIGH
Truck 7: Ram 150023.88 HIGH
Overall fleet MPG: 20.54
Trucks with high MPG: 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

5. How can we use language to enhance skill in perceiving?

Answered: 1 week ago

Question

What actions might have prevented Bobs resignation?

Answered: 1 week ago