Test Index
CBSE Class 12 Computer Science 2026 Paper Set 4
© examsnet.com
Question : 32 of 37
Marks:
+1,
-0
Abhishek has created a table, named STOCK, with a set of records to maintain the data of packaged milk in his shop. After creating the table, he entered the data and the table looked as follows :
(a) Based on the data given above, write the SQL queries for the following tasks :(i) To display Type and the maximum Price for each Type of milk.(ii) For each record, increase the Price by 0.5 where Type is 'F'.(iii) To display the total value of the stock (total of Qty × Price).(iv) To display the details of all records where Code starts with 'A'.OR(b) Considering the table STOCK as given above, write the output on execution of the following queries :(i)
| Code | Type | Volume | Qty | Price |
|---|---|---|---|---|
| AF0.5 | F | 0.5 | 300 | 38.00 |
| MF0.5 | F | 0.5 | 250 | 36.50 |
| MT1.0 | T | 1.0 | 150 | 64.00 |
| AT1.0 | T | 1.0 | 100 | 66.00 |
| PD1.0 | D | 1.0 | 50 | 52.00 |
| PT0.5 | T | 0.5 | 78 | 30.00 |
SELECT Volume, Qty, Price FROM STOCK WHERE Type IN ('F','D');(ii)SELECT Code, Qty FROM STOCK WHERE Price BETWEEN 30 AND 50;(iii)
SELECT DISTINCT Type FROM STOCK;(iv)
SELECT Volume, count(*) FROM STOCK GROUP BYVolume;
Solution:
(a)(i) GROUP BY makes one group per Type; MAX(Price) gives the highest price in each group.
(b)(ii) BETWEEN 30 AND 50 includes both end values: 38.00, 36.50 and 30.00 qualify (64.00, 66.00 and 52.00 do not).
(b)(iii) DISTINCT shows each Type only once.
(b)(iv) Rows are grouped by Volume and counted: 0.5 occurs in AF0.5, MF0.5, PT0.5; 1.0 occurs in MT1.0, AT1.0, PD1.0.
SELECT Type, MAX(Price) FROM STOCKGROUP BY Type;(a)(ii) UPDATE changes the stored rows; the WHERE clause limits the change to Type 'F'.
UPDATE STOCKSET Price = Price + 0.5WHERE Type = 'F';(a)(iii) Qty * Price is the value of one row; SUM adds it over all rows.
SELECT SUM(Qty * Price) FROM STOCK;(For the given data: 11400 + 9125 + 9600 + 6600 + 2600 + 2340 = 41665.)(a)(iv) In LIKE, % stands for any number of characters, so 'A%' means “starts with A”.
SELECT * FROM STOCKWHERE Code LIKE 'A%';OR (b)(b)(i) Rows with Type F or D: AF0.5, MF0.5 and PD1.0.
| Volume | Qty | Price |
|---|---|---|
| 0.5 | 300 | 38.00 |
| 0.5 | 250 | 36.50 |
| 1.0 | 50 | 52.00 |
| Code | Qty |
|---|---|
| AF0.5 | 300 |
| MF0.5 | 250 |
| PT0.5 | 78 |
| Type |
|---|
| F |
| T |
| D |
| Volume | count(*) |
|---|---|
| 0.5 | 3 |
| 1.0 | 3 |
© examsnet.com
Go to Question: