Skip to content
Exercises · Q4

Q.Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following:

(a) Add a new column Discount in the INVENTORY table.
(b) Set appropriate discount values for all cars keeping in mind the following:
(i) No discount is available on the LXI model.
(ii) VXI model gives a 10% discount.
(iii) A 12% discount is given on cars other than the LXI model and VXI model.
(c) Display the name of the costliest car with fuel type "Petrol".
(d) Calculate the average discount and total discount available on Car4.
(e) List the total number of cars having no discount.
Tamil Nadu DgeTextbookSubjective· 5mImportance★★★★★
45% · 18/40 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Every part of this exercise runs against the real 8-row INVENTORY table already established in this chapter (§1.1) — never a hypothetical or assumed schema.

This is a code/query task. Starting data (Table 1.1, INVENTORY):

CarIdCarNamePriceModelYearManufactureFuelType
D001Car1582613.00LXI2017Petrol
D002Car1673112.00VXI2018Petrol
B001Car2567031.00Sigma1.22019Petrol
B002Car2647858.00Delta1.22018Petrol
E001Car3355205.005 STR STD2017CNG
E002Car3654914.00CARE2018CNG
S001Car4514000.00LXI2017Petrol
S002Car4614000.00VXI2018Petrol

(a) Add the column with ALTER TABLE:

ALTER TABLE INVENTORY ADD Discount Numeric(5,2);

(b) A CASE expression assigns a different discount per model in a single UPDATE:

UPDATE INVENTORY SET Discount =
    CASE
        WHEN Model='LXI' THEN 0
        WHEN Model='VXI' THEN 10
        ELSE 12
    END;

Applying this to every row: LXI cars (D001, S001) get 0; VXI cars (D002, S002) get 10; everything else — Sigma1.2, Delta1.2, 5 STR STD, CARE (B001, B002, E001, E002) — gets 12:

CarIdCarNameModelPriceDiscount
D001Car1LXI582613.000
D002Car1VXI673112.0010
B001Car2Sigma1.2567031.0012
B002Car2Delta1.2647858.0012
E001Car35 STR STD355205.0012
E002Car3CARE654914.0012
S001Car4LXI514000.000
S002Car4VXI614000.0010

(c) Filter to Petrol, sort by Price descending, keep only the top row:

SELECT CarName FROM INVENTORY WHERE FuelType='Petrol' ORDER BY Price DESC LIMIT 1;

Petrol cars are D001, D002, B001, B002, S001, S002 (E001 and E002 are CNG). Their prices: 582613, 673112, 567031, 647858, 514000, 614000. The highest is D002 at 673112.00, whose CarName is "Car1". …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.