CERTIFICATE
SIGNATURE
Consider the following tables Product and Client. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
TABLE: Product
TABLE: Clients
A. SQL Commands:
i. To display the details of those clients whose city is Delhi
ii. To display the details of Products whose price is in the range of 50 to 100 (Both
values included)
iii. To display the ClientName, City from table Client, and ProductName and Price from
table Products with their corresponding matching P_ID.
iv. To increase the Price of all Products by 10.
B. OUTPUT Queries:
v. SELECT DISTINCT city FROM client;
vi. SELECT manufacturer, Max(price), Min(price), Count (*)
FROM product
GROUP BY manufacturer;
vii. SELECT clientname, productname
FROM product, client;
WHERE client.p_id = product.p_id;
viii. SELECT productname, price * 4
FROM product;
CREATING TABLES:
PRODUCT
CREATE TABLE Product (P_ID varchar (10), ProductName char (30), Manufacturer char
(30), Price int);
INSERT INTO Product VALUES('TP01', 'Talcom Powder', 'LAK', 40);
INSERT INTO Product VALUES('FW05', 'Face Wash', 'ABC', 45);
INSERT INTO Product VALUES('BS01', 'Bath Soap', 'ABC', 55);
INSERT INTO Product VALUES('SH06', 'Shampoo', 'XYZ', 120);
INSERT INTO Product VALUES('FW12', 'Face Wash', 'XYZ', 95);
CLIENTS
ii. SELECT *
FROM product
WHERE price BETWEEN 50 AND 100;
Consider the following tables Product and Client. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
TABLE: Consignor
TABLE: Consignee
A. SQL Commands:
i. To display the names of all Consignors from Mumbai
ii. To display the CneeID, CnorName, CnorAddress, CneeName, CneeAddress for
corresponding Cnor_ID
iii. To display consignee details in ascending order of CneeName
iv. To display number of consignors from each city
B. OUTPUT Queries:
v. SELECT DISTINCT City FROM Consignor;
vi. SELECT A.CnorName, B.CneeName FROM Consignor A, Consignee B
WHERE A.CnorID = B.CnorID and B.CneeCity = 'Mumbai';
vii. SELECT CneeName, CneeAddress FROM Consignee
WHERE CneeCity NOT IN ('Mumbai', 'Kolkata');
viii. SELECT CneeID, CneeName FROM Consignee
WHERE CnorID = 'MU15' OR CnorID = 'ND01';
CREATING TABLES:
CONSIGNOR
CONSIGNEE
i. SELECT cnorname
FROM consignor
WHERE City = 'Mumbai';
iii. SELECT *
FROM Consignee
ORDER BY CneeName;
iv. SELECT CneeCity, Count(CneeCity)
FROM Consignee
GROUP BY CneeCity
Consider the following tables Stock and Dealers and answer (a1) and (a2) parts of
this question.
Table: Stock
Table: Dealers
A. SQL Commands:
i. To display details of all Items in the Stock table in ascending order of StockDate
ii. To display ItemNo and Item name of those items from Stock table whose
UnitPrice is more than Rupees 10.
iii. To display the details of those items whose dealer code (Dcode) is 102 or
Quantity in Stock (Qty) is more than 100 from the table Stock.
iv. To display Maximum UnitPrice of items for each dealer individually as per Dcode
from the table stock.
B. OUTPUT Queries:
v. SELECT COUNT(DISTINCT Dcode) FROM Stock;
vi. SELECT Qty*UnitPrice from Stock
WHERE ItemNo = 5006;
vii. SELECT Item, Dname FROM Stock S, Dealer D
WHERE S.Dcode = D.Dcode AND ItemNo = 5004;
viii. SELECT MIN(StockDate) FROM Stock;
CREATING TABLES:
STOCK
DEALERS
Consider the following tables EMPLOYEE and SALGRADE and answer (A) and
(B) parts of this question.
Table: EMPLOYEE
Table: SALGRADE
A. SQL Commands:
i. To display the details of all Employees in descending order of DOJ.
ii. To display NAME and DESIG of those Employees, whose SALGRADE is either
S02 or S03.
iii. To display the content of all the employees table, whose DOJ is in between '09-
Feb-2006' and '08-Aug-2009'.
iv. To add a new row with the following: 19, 'Harish Roy', 'HEAD-IT', 'S02', '09-
Sep-2007', '21-Apr-1983'.
B. Output Queries:
v. SELECT COUNT (Sgrade), Sgrade from employee group by sgrade;
vi. SELECT MIN(DOB), MAX(DOJ) FROM Employee;
vii. SELECT Name, Salary from Employee E,
SALGRADE S WHERE E.Sgrade = S.sgrade and E.Ecode<103;
viii. SELECT SGRADE, SALARY + HRA FROM SALGRADE WHERE SGRADE
= 'S02';
CREATING TABLES:
EMPLOYEE
SALGRADE
iv. INSERT INTO Employee VALUES(19, 'Harish Roy', 'HEAD-IT', 'S02', '09-Sept-2007',
'21-Apr-1983');
Consider the following tables STORES AND ITEM and answer (A) and (B) parts
of this question.
Table: STORE
Table: ITEM
A. SQL Commands:
i. To display Iname and Price of all the Items in ascending order of their price.
ii. To display SNo and SName of all Stores located in CP.
iii. To display minimum and maximum price of each IName from the table Item.
iv. To display IName, Price of all items and their respective SName where they are
available.
B. Output Queries:
v. SELECT DISTINCT INAME FROM ITEM WHERE PRICE >= 5000;
vi. SELECT AREA, COUNT (*) FROM STORE GROUP BY AREA;
vii. SELECT COUNT(DISTINCT AREA) FROM STORE;
viii. SELECT INAME, PRICE * 0.05 DISCOUNT FROM ITEM WHERE SNO IN
('S02', 'S03')
CREATING TABLES:
STORE
CREATE table STORE(Sno varchar(3) not null primary key,SName char(40),Area char(20));
INSERT INTO STORE VALUES ('S01','ABC Copmutronics','GK II');
INSERT INTO STORE VALUES ('S02','All Infotech Media','CP');
INSERT INTO STORE VALUES ('S03','Tech Shoppe','Nehru Place');
INSERT INTO STORE VALUES ('S04','Geeks Techo Soft','Nehru Place');
INSERT INTO STORE VALUES ('S05','Hitech Tech Store','CP');
ITEM
CREATE table ITEM(INo varchar(3) not null primary key,IName char(20),Price int,SNo
varchar(3));
INSERT INTO ITEM VALUES ('T01','Mother Board',12000,'S01');
INSERT INTO ITEM VALUES ('T02','Hard Disk',5000,'S01');
INSERT INTO ITEM VALUES ('T03','Keyborad',500,'S02');
INSERT INTO ITEM VALUES ('T04','Mouse',300,'S01');
INSERT INTO ITEM VALUES ('T05','Mother Board',13000,'S02');
INSERT INTO ITEM VALUES ('T06','Keyboard',400,'S03');
INSERT INTO ITEM VALUES ('T07','LCD',6000,'S04');
INSERT INTO ITEM VALUES ('T08','LCD',5500,'S05');
INSERT INTO ITEM VALUES ('T09','Mouse',350,'S05');
INSERT INTO ITEM VALUES ('T10','Hard Disk',4500,'S03');
ANSWERS:
i. SELECT IName,Price FROM ITEM
ORDER BY Price;
viii. SELECT INAME, PRICE * 0.05 DISCOUNT FROM ITEM WHERE SNO IN ('S02',
'S03')
QUESTION 6
Consider the following tables Item and Customer. Write answer for the statement
(i) to (viii).
TABLE: CUSTOMER
TABLE: ITEM
A. SQL Commands:
i. To display the details of those customers whose city is Delhi.
ii. To display the details of item whose price is in the range of 35000 to 55000 (both values
included).
iii. To display the customer name, city from table Customer, and ItemName and Price from
table Item, with their corresponding i_ID.
iv. To increase the price of all items by 1000 in the table Item.
B. Output Queries:
v. SELECT DISTINCT CITY FROM CUSTOMER;
vi. SELECT ITEMNAME, MAX(PRICE), COUNT(*) FROM ITEM GROUP BY
ITEMNAME;
vii. SELECT CustomerName, Manufacturer from Item, Customer WHERE
Item.I_id=Customer.I_id;
viii. SELECT ItemName,Price * 100 From Item WHERE Manufacturer='ABC';
CREATING TABLES:
CUSTOMER
ITEM
ii) SELECT * FROM ITEM WHERE PRICE BETWEEN 35000 AND 55000;
Consider the following tables SENDER AND RECIPIENT and answer (A) and (B)
parts of this question
TABLE: SENDER
TABLE: RECIPIENT
A. SQL Commands:
i. To display the names of all senders from Mumbai.
ii. To display the recID, senderName, senderAddress, RecName, RecAddress for
every recipt.
iii. To display the sender details in ascending order of SenderName.
iv. To display number of Recipients from each city.
B. Output Queries:
v. SELECT DISTINCT SenderCity FROM Sender;
vi. SELECT A.SenderName A, B.RecName FROM Sender A, Recipient B
WHERE A.SenderID=B. SenderID AND B.RecCity='Mumbai';
vii. SELECT RecName,RecAddress FROMRecipient WHERE RecCity Not IN
('Mumbai',Kolkata');
viii. SELECT RecID, RecName FROM Recipient WHERE SenderID = 'MU02' OR
SenderID = 'ND50';
CREATING TABLES:
SENDER
RECIPIENT
viii. SELECT RecID, RecName FROM Recipient WHERE SenderID = 'MU02' OR SenderID
= 'ND50';
INDEX
S.no Topic
1. Structures