Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 41 of 58
Marks:
+1,
-0
Consider the table Stationery given below and write the output of the SQL queries that follow.Table : Stationery
(i)
| ITEMNO | ITEM | DISTRIBUTOR | QTY | PRICE |
|---|---|---|---|---|
| 401 | Ball Pen 0.5 | Reliable Stationers | 100 | 16 |
| 402 | Gel Pen Premium | Classic Plastics | 150 | 20 |
| 403 | Eraser Big | Clear Deals | 210 | 10 |
| 404 | Eraser Small | Clear Deals | 200 | 5 |
| 405 | Sharpener Classic | Classic Plastics | 150 | 8 |
| 406 | Gel Pen Classic | Classic Plastics | 100 | 15 |
SELECT DISTRIBUTOR, SUM(QTY) FROM STATIONERY GROUP BY DISTRIBUTOR;(ii) SELECT ITEMNO, ITEM FROM STATIONERY WHERE DISTRIBUTOR = "Classic Plastics" AND PRICE > 10;(iii) SELECT ITEM, QTY * PRICE AS "AMOUNT" FROM STATIONERY WHERE ITEMNO = 402;[CBSE 2024 Compartment]
Solution:
(i)
(ii) Rows of Classic Plastics are 402 (price 20), 405 (price 8) and 406 (price 15); only those with PRICE > 10 are kept, so 405 is dropped.
(iii) For ITEMNO 402: AMOUNT = QTY × PRICE = 150 × 20 = 3000. The alias
GROUP BY DISTRIBUTOR makes one group per distributor and SUM(QTY) adds the quantities in each group: Classic Plastics = 150 + 150 + 100 = 400, Clear Deals = 210 + 200 = 410.| DISTRIBUTOR | SUM(QTY) |
| Reliable Stationers | 100 |
| Classic Plastics | 400 |
| Clear Deals | 410 |
| ITEMNO | ITEM |
| 402 | Gel Pen Premium |
| 406 | Gel Pen Classic |
AS "AMOUNT" becomes the column heading.| ITEM | AMOUNT |
| Gel Pen Premium | 3000 |
© examsnet.com
Go to Question: