Skip to content
Worked Examples · Example 1.5

Q.Using the INVENTORY table of the CARSHOWROOM database and the aggregate functions in SQL:

(a) Display the total number of records from the INVENTORY table having a Model as VXI.
(b) Display the total number of different types of Models available in the INVENTORY table.
(c) Display the average price of all the cars with Model LXI from the INVENTORY table.
Uttar Pradesh UpmspTextbookSubjective· 4mImportance★★★★★
23% · 9/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 →

Three aggregate-function queries on the real 8-row INVENTORY table: COUNT(*) with a WHERE filter, COUNT(DISTINCT ...) for unique values, and AVG() with a WHERE filter.

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

(a) COUNT(*) with a WHERE clause counts only the matching rows:

SELECT COUNT(*) FROM INVENTORY WHERE Model="VXI";

Scanning the Model column: D002 and S002 are VXI — 2 rows.

(b) COUNT(DISTINCT column) counts unique values, ignoring repeats:

SELECT COUNT(DISTINCT Model) FROM INVENTORY;

The 8 rows carry these Model values: LXI, VXI, Sigma1.2, Delta1.2, 5 STR STD, CARE, LXI, VXI — LXI and VXI each repeat twice, so the distinct count is 6. …

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.