Test Index

CBSE Class 12 Computer Science 2026 Paper Compartment Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 32 of 37
Marks: +1, -0
TechMart Inc. manages its product inventory using an SQL table named PRODUCTS. The table consists of the attributes PID, PName, Category, Price, Quantity, and LastUpdated, and contains the following records:
Table : PRODUCTS
PIDPNameCategoryPriceQuantityLastUpdated
101Laptop ProElectronics1200502024-01-10
102Gaming MousePeripherals45.992002023-11-25
103Ergonomic KeyboardPeripherals751502024-02-01
104Smart SpeakerElectronics89.991002024-01-15
105USB-C HubAccessories29.53002023-12-05
106External SSD 1TBStorage99752024-03-01
107Wireless EarbudsAudio129.991202024-02-10
108Desk LampHome351802023-10-20
109Web Camera HDPeripherals60NULL2024-01-25
110Portable ChargerAccessories49.992502023-12-15
(a) Based on the data given above answer the following questions :
(I) Write the SQL statement to display the PName and Price of those PRODUCTS that belong to the 'Electronics' category and have a Price greater than 100.00.
(II) Write the SQL statement to display the Category and the total number of products in each category.
(III) Write the SQL statement to display the entire PRODUCTS table content, in ascending order of Last date of Updation (showing the earliest updates first).
(IV) Write the SQL statement to make the Price of all PRODUCTS whose quantity is not known, to 0.
OR
(b) Considering the above given table PRODUCTS, write the output on execution of the following SQL commands:
(I)
SELECT Avg(Quantity) FROM PRODUCTS
WHERE Category = 'Peripherals';
(II)
SELECT DISTINCT Category FROM PRODUCTS;
(III)
SELECT COUNT(PID) FROM PRODUCTS
WHERE Quantity < 100;
(IV)
SELECT PName, Category FROM PRODUCTS
WHERE PName LIKE '%Speaker%';
Solution:  
(a)
(a)(I) Both conditions must hold, so join them with AND.
SELECT PName, Price FROM PRODUCTS
WHERE Category = 'Electronics' AND Price > 100.00;
(Only Laptop Pro, 1200, qualifies; Smart Speaker costs 89.99.)
(a)(II) GROUP BY makes one group per category and COUNT(*) counts the rows in each group.
SELECT Category, COUNT(*) FROM PRODUCTS
GROUP BY Category;
(a)(III) ORDER BY sorts in ascending order by default (ASC may be written).
SELECT * FROM PRODUCTS
ORDER BY LastUpdated ASC;
(a)(IV) An unknown quantity is stored as NULL, and NULL is tested with IS NULL (never with = NULL).
UPDATE PRODUCTS SET Price = 0
WHERE Quantity IS NULL;
(This changes only PID 109, Web Camera HD.)
OR (b)
(b)(I) Peripherals rows: Quantity 200, 150 and NULL. Aggregate functions ignore NULL, so AVG = (200 + 150) / 2 = 175.
Avg(Quantity)
175.0000
(Written as 175 or 175.0 is equally correct; MySQL shows 175.0000.)
(b)(II) Each category is shown once:
Category
Electronics
Peripherals
Accessories
Storage
Audio
Home
(b)(III) Quantity < 100: Laptop Pro (50) and External SSD 1TB (75). The NULL quantity of Web Camera HD is not counted, because NULL < 100 is not true. 100 itself is not less than 100.
COUNT(PID)
2
(b)(IV) % matches any number of characters, so the pattern finds every name that contains "Speaker" anywhere:
PNameCategory
Smart SpeakerElectronics
Key point: NULL never satisfies a comparison (=, < , >) and is skipped by AVG, SUM and COUNT(column); only IS NULL / IS NOT NULL test it.
© examsnet.com
Advertisements
Go to Question: