Test Index
CBSE Class 12 Computer Science 2026 Paper Compartment
© 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
(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)
| PID | PName | Category | Price | Quantity | LastUpdated |
| 101 | Laptop Pro | Electronics | 1200 | 50 | 2024-01-10 |
| 102 | Gaming Mouse | Peripherals | 45.99 | 200 | 2023-11-25 |
| 103 | Ergonomic Keyboard | Peripherals | 75 | 150 | 2024-02-01 |
| 104 | Smart Speaker | Electronics | 89.99 | 100 | 2024-01-15 |
| 105 | USB-C Hub | Accessories | 29.5 | 300 | 2023-12-05 |
| 106 | External SSD 1TB | Storage | 99 | 75 | 2024-03-01 |
| 107 | Wireless Earbuds | Audio | 129.99 | 120 | 2024-02-10 |
| 108 | Desk Lamp | Home | 35 | 180 | 2023-10-20 |
| 109 | Web Camera HD | Peripherals | 60 | NULL | 2024-01-25 |
| 110 | Portable Charger | Accessories | 49.99 | 250 | 2023-12-15 |
SELECT Avg(Quantity) FROM PRODUCTSWHERE Category = 'Peripherals';(II)
SELECT DISTINCT Category FROM PRODUCTS;(III)
SELECT COUNT(PID) FROM PRODUCTSWHERE Quantity < 100;(IV)
SELECT PName, Category FROM PRODUCTSWHERE PName LIKE '%Speaker%';
Solution:
(a)(a)(I) Both conditions must hold, so join them with AND.
(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.
Key point: NULL never satisfies a comparison (=, < , >) and is skipped by AVG, SUM and COUNT(column); only IS NULL / IS NOT NULL test it.
SELECT PName, Price FROM PRODUCTSWHERE 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 PRODUCTSGROUP BY Category;(a)(III) ORDER BY sorts in ascending order by default (ASC may be written).
SELECT * FROM PRODUCTSORDER 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 = 0WHERE 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 |
COUNT(PID)2(b)(IV)
% matches any number of characters, so the pattern finds every name that contains "Speaker" anywhere:| PName | Category |
| Smart Speaker | Electronics |
© examsnet.com
Go to Question: