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
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:
| 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 |
(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.