Sql problems (1) 1
Sql problems (1) 1
Consider the table DRUGDB. Write the SQL commands for queries given below:
(i) To increase the price of “Paracetamol” by 35.
(ii) To display the drugid, Rxid and pharmacy name of all records in descending order of their
price.
(iii) Display all the details of the drugs where name starts with ‘C’ and has ‘sh’ somewhere in the
name.
(iv) Display the drug name in lower case along with price rounded off to nearest interger.
(v) Delete the field name loc from drugdb table.
Items VARCHAR(100),
DatePurchase DATE,
Discount DECIMAL(5, 2)
);
VALUES
Output generation:
3. Write the commands in SQL for (i) to (v) and output for (vi) and (vii).
5.Consider the following tables Product and Client .Write SQL commands for the statement i to iv
Table : Product
P_ID Product Name Manufacturer Price
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95
Table : Client
C_ID Client Name City P_ID
01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty Woman Delhi FW12
16 Dreams Bangalore TP01
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
iii) To display the Clientname,City from table client, and ProductName and Pricefrom table
Product, with their corresponding matching P_ID.
iv) To increase the Price of all products by 10.
use arp;
create table product
(P_ID char(4),
Product_Name char(20),
Manufacture char(4),
Price int);
create table
client (C_ID
char(4),
Client_Name char(20),
City char(10),
P_id char(4));
6. Consider the following tables Stock and Dealers .Write SQL commands for the statement i to v
Table : Stock
ItemNo Item DCode Qty UnitPrice StockDate
5005 Ball Pen 0.5 102 100 16 31-Mar-
10
5003 Ball Pen 0.25 102 150 20 01-Jan-10
5002 Gel Pen 101 125 14 14-Feb-10
Premium
5006 Gel 101 200 22 01-Jan-09
Pen
Classic
5001 Eraser Small 102 210 5 19-Mar-
09
5004 Eraser Big 102 60 10 12-Dec-
09
5009 Sharpener 103 160 8 23-Jan-09
Classic
Table : Dealer
DCode DName
101 Reliable
Stationaries
103 Classic Plastics
102 Clear Deals
i) To display the details of all items in the Stock table in ascending order of StockDate
ii) To display ItemNo and ItemName of those items from the Stock table where UnitPrice
is more than Rupees 10
iii) To display the details of those items whose dealer code is 102 or Qty is more than 100
iv) To display Maximum UnitPrice of items for each dealer individually as per DCode from
the table Stock
v) To display the count of all items from the table Stock and group by Item
Create database d;
use d;
1)
2)
3)
4)
5)
5. Consider the following tables Books and Issued
Table : Books
Book_ Publishers Book_name Author_name Pri Type Qty
ID ce
C0001 EPB Fast Cook Lata Kapoor 35 Cookery 5
5
F0001 First Publ The tears William 65 Fiction 20
Hopkins 0
T0001 EPB My First C++ Brian & 35 Text 10
Brooke 0
T0002 TDH C++ Brain AW 35 Text 15
works Rossaine 0
F0002 First Publ Thunderbolts Anna Roberts 75 Fiction 50
0
Table : Issued
Book_ID Quantity_Issued
T0001 4
C0001 5
F0001 2
Write the sql commands for the following
i) To show Book_name, Author_name and price of the books of First Publ Book_name
ii) To list the names from books of the text type
iii)To list the names and price from books in ascending order of their price.
iv) To increase the price of all books of EPB publisher by 50
v) To display the Book_ID ,Book_name and Quantity_Issued for all books which have been
issued.
vi) To insert a new row in the table issued having the following data:”F003”,1
Create database
d;
Use d;
Create table
Books (
Book_ID varchar(5),
Book_Name varchar(20),
Author_Name varchar(20),
Publisher varchar(20),
Price integer,
Type char(10),
Qty integer);
Insert into Books values(‘C0001’,”EPB”,”Fast Cook”,”Latha Kapoor”,355,”cookery”,5);
Insert into Books values('F0001','First Publ','The tears','William Hopkins',650,'Fict',20);
Insert into Books values('T0001','EPB','My First C++',"Brian & Brooks",350,"text",15);
Insert into Books values('T0002',"EPB","C++ BrianWorks","A W ROSSAINE",350,"Text",50);
Insert into Books values('F0002',"First Publ","ThunderBolts","Anna Roberts",650,"Fict",50);
Create table
Issued (
Bookid varchar(3),
Quantity_issued integer
);
Insert into Issued values('T01',4);
Insert into Issued values('C01',5);
Insert into Issued values('F01',2);