Skip to content
Activities · Activity 1.2

Q.Using the table INVENTORY from CARSHOWROOM database, write sql queries for the following:

(a) Convert the CarMake to uppercase if its value starts with the letter ‘B’.
(b) If the length of the car’s model is greater than 4 then fetch the substring starting from position 3 till the end from attribute Model.
Yanam BieapTextbookSubjective· 3mImportance★★★★★est
10% · 4/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 →

A CASE expression picks between UPPER(CarName) and the original value based on a LIKE 'B%' test, and between SUBSTRING(Model, 3) and the original value based on LENGTH(Model) > 4 — both on the real INVENTORY table.

This is a code/query task on the INVENTORY table of CARSHOWROOM:

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

The book's own Activity 1.2 text says "CarMake," but the INVENTORY table it defines (Table 1.1) has no such column — only CarName. Treating "CarMake" as CarName is the only sensible reading, since that's the chapter's real string attribute on this table.

(a) LIKE 'B%' tests whether a string starts with 'B'; UPPER() converts to uppercase:

SELECT CASE WHEN CarName LIKE 'B%' THEN UPPER(CarName) ELSE CarName END FROM INVENTORY;

Checking every CarName — Car1, Car2, Car3, Car4 — none starts with 'B', so the ELSE branch fires every time and every name comes back unchanged.

(b) LENGTH() measures the string; SUBSTRING(string, 3) (two-argument form) returns everything from position 3 to the end:

SELECT CASE WHEN LENGTH(Model) > 4 THEN SUBSTRING(Model, 3) ELSE Model END FROM INVENTORY;
``` …

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.