Test Index

Structured Query Language (SQL) Get it on Google PlayDownload on the App Store CBSE Board Videos

© 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
ITEMNOITEMDISTRIBUTORQTYPRICE
401Ball Pen 0.5Reliable Stationers10016
402Gel Pen PremiumClassic Plastics15020
403Eraser BigClear Deals21010
404Eraser SmallClear Deals2005
405Sharpener ClassicClassic Plastics1508
406Gel Pen ClassicClassic Plastics10015
(i) 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) 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.
DISTRIBUTORSUM(QTY)
Reliable Stationers100
Classic Plastics400
Clear Deals410
(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.
ITEMNOITEM
402Gel Pen Premium
406Gel Pen Classic
(iii) For ITEMNO 402: AMOUNT = QTY × PRICE = 150 × 20 = 3000. The alias AS "AMOUNT" becomes the column heading.
ITEMAMOUNT
Gel Pen Premium3000
© examsnet.com
Advertisements
Go to Question: