Skip to content
Activities · Activity 9.11

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.
Tamil Nadu DgeTextbookSubjective· 4mImportance★★★★★est
23% · 22/95 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 →

Use IF() (or CASE) with UPPER() and SUBSTRING()/LENGTH() to transform column values conditionally, applied to the real INVENTORY table (Table 9.9) of the CARSHOWROOM database — the real name column is CarName (there is no CarMake column in this schema).

The real INVENTORY table (Table 9.9)

CarIdCarNameModel
D001DzireLXI
D002DzireVXI
B001BalenoSigma1.2
B002BalenoDelta1.2
E001EECO5 STR STD
E002EECOCARE
S001SWIFTLXI
S002SWIFTVXI

(a) Convert the CarName to uppercase if its value starts with the letter 'B'

SELECT
    IF(CarName LIKE 'B%', UPPER(CarName), CarName) AS CarName
FROM INVENTORY;

Key logic: CarName LIKE 'B%' tests whether the name starts with 'B'. Only Baleno (B001, B002) starts with 'B' among the real car names (Dzire, Baleno, EECO, SWIFT); the other three names are left unchanged.

Output

CarIdCarName
D001Dzire
D002Dzire
B001BALENO
B002BALENO
E001EECO
E002EECO
S001SWIFT
S002SWIFT

(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

SELECT
    CarId,
    IF(LENGTH(Model) > 4, SUBSTRING(Model, 3), Model) AS Model
FROM INVENTORY;

Key logic: LENGTH(Model) is checked against 4. LXI, VXI (length 3) and CARE (length 4, not greater than 4) stay unchanged. Sigma1.2, Delta1.2 (length 8) and 5 STR STD (length 9, counting the two spaces) all exceed 4 and get truncated from position 3 onward.

Output …

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.