Tuesday, 10 September 2024

SQL-1

 create database CSIP;

us CSIP;

consider the table ORDERS given below and write the output of the SQL queries that follow


CREATE TABLE ORDERS(ORDNO INTEGER PRIMARY KEY, ITEM VARCHAR(12),QTY INTEGER, RATE INTEGER, ORDATE DATE);





DESC ORDERS;\






INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1001,'RICE',23,120,'2023-09-10');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1002,'PULSES',13,120,'2023-10-18');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1003,'RICE',25,110,'2023-11-17');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1004,'WHEAT',28,120,'2023-12-25');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1005,'PULSES',16,110,'2024-01-15');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1006,'WHEAT',27,55,'2024-04-15');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1007,'WHEAT',25,60,'2024-04-30');


SELECT * FROM ORDERS;


(i) SELECT ITEM, SUM(QTY) FROM ORDERS GROUP BY ITEM;

Ans.


(ii) SELECT ITEM, QTY FROM ORDERS WHERE  ORDATE BETWEEN '2023-11-01' AND '2023-12-31';

Ans.






(iii) SELECT  ORDNO, ORDATE FROM ORDERS WHERE ITEM = 'WHEAT' AND RATE >=60;
Ans.














No comments:

Post a Comment