Q.Using the table INVENTORY from CARSHOWROOM database, write sql queries for the following:
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:
| CarId | CarName | Price | Model | YearManufacture | FuelType |
|---|---|---|---|---|---|
| D001 | Car1 | 582613.00 | LXI | 2017 | Petrol |
| D002 | Car1 | 673112.00 | VXI | 2018 | Petrol |
| B001 | Car2 | 567031.00 | Sigma1.2 | 2019 | Petrol |
| B002 | Car2 | 647858.00 | Delta1.2 | 2018 | Petrol |
| E001 | Car3 | 355205.00 | 5 STR STD | 2017 | CNG |
| E002 | Car3 | 654914.00 | CARE | 2018 | CNG |
| S001 | Car4 | 514000.00 | LXI | 2017 | Petrol |
| S002 | Car4 | 614000.00 | VXI | 2018 | Petrol |
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.