Test Index
Structured Query Language (SQL)
© examsnet.com
Question : 35 of 58
Marks:
+1,
-0
Consider the table ORDERS given below and write the output of the SQL queries that follow :
(i)
ORDNO | ITEM | QTY | RATE | ORDATE |
|---|---|---|---|---|
1001 | RICE | 23 | 120 | 2023-09-10 |
1002 | PULSES | 13 | 120 | 2023-10-18 |
1003 | RICE | 25 | 110 | 2023-11-17 |
1004 | WHEAT | 28 | 65 | 2023-12-25 |
1005 | PULSES | 16 | 110 | 2024-01-15 |
1006 | WHEAT | 27 | 55 | 2024-04-15 |
1007 | WHEAT | 25 | 60 | 2024-04-30 |
SELECT ITEM, SUM(QTY) FROM ORDERS GROUP BY ITEM;(ii) SELECT ITEM, QTY FROM ORDERS WHERE ORDATE BETWEEN '2023-11-01' AND '2023-12-31';(iii) SELECT ORDNO, ORDATE FROM ORDERS WHERE ITEM = 'WHEAT' AND RATE>=60;[CBSE 2024 Set 4]
Solution:
(i) Rows are grouped by ITEM and QTY is added in each group:
(RICE 23 + 25, PULSES 13 + 16, WHEAT 28 + 27 + 25)(ii) Orders dated from 1 Nov 2023 to 31 Dec 2023 (both included):
(iii) WHEAT orders with RATE 60 or more (1006 has rate 55, so it is left out):
| ITEM | SUM(QTY) |
| RICE | 48 |
| PULSES | 29 |
| WHEAT | 80 |
| ITEM | QTY |
| RICE | 25 |
| WHEAT | 28 |
| ORDNO | ORDATE |
| 1004 | 2023-12-25 |
| 1007 | 2024-04-30 |
© examsnet.com
Go to Question: