database practical questions 5 set queries
database practical questions 5 set queries
ent. Write SQL commands for the statement (i) to (iv) and give
outputs for SQL queries (v) to (viii).
Table: PRODUCT
Product
P_ID Manufacturer Price
Name
TP01 TalcomPowder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95
Table: CLIENT
(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 Product, with their
corresponding matching P_ID.
Ans:
City
Delhi
Mumbai
Bangalore
(vi) SELECT Manufacturer, MAX(Price), Min(Price), Count(*) FROM Product GROUP BY Manufacturer;
Ans:
Ans:
ClientName ManufacturerName
CosmeticShop ABC
TotalHealth ABC
LiveLife XYZ
PrettyWoman XYZ
Dreams LAK
Ans:
ProductName Price*4
TalcomPoweder 160
FaceWash 180
BathSoap 220
Shampoo 480
Face Wash 380
Q2. Consider the following tables Item and Customer. Write SQL commands for the statement (i) to (iv) and give
outputs for SQL queries (v) to (viii). Table: ITEM
Table: CUSTOMER
(ii) To display the details of Item whose Price is in the range of 35000 to 55000 (Both values included).
(iii) To display the CustomerName, City from table Customer, and ItemName and Price from table Item, with their
corresponding matching I_ID.
(iv) To increase the Price of all Items by 1000 in the table Item.
Ans:
City
Delhi
Mumbai
Bangalore
(vi) SELECT ItemName, MAX(Price), Count(*) FROM Item GROUP BY ItemName;
Ans:
PersonalComputer 37000 3
Laptop 57000 2
Ans:
(viii) SELECT ItemName, Price * 100 FROM Item WHERE Manufacturer = ‘ABC’;
Ans:
ItemName Price*100
PersonalComputer 3500000
Laptop 5500000
Q3. Consider the following tables Consignor and Consignee. Write SQL command for the statements(i)to(iv) And give
outputs for the SQL quries (v) to ( viii).
TABLE : CONSIGNOR
TABLE : CONSIGNEE
(ii) To display the cneeID, cnorName, cnorAddress, CneeName, CneeAddress for every Consignee.
Ans: Select CneeId, CnorName, CnorAddress, CneeName, CneeAddress from Consignor,Consignee where
Consignor.CnorId=Consignee.CnorId;
Ans:
CneeCity
Mumbai
New Delhi
Kolkata
(vi) SELECT A.CnorName, B.CneeName FROM Consignor A, Consignee B WHERE A.CnorID=B.CnorID AND
B.CneeCity=’Mumbai’;
Ans:
CnorName CneeName
(vii) SELECT CneeName,CneeAddress FROM Consignee WHERE CneeCity Not IN (‘Mumbai’, ‘Kolkata’);
Ans:
CneeName CneeAddress
P Dhingr a 16/j,Moore Enclave
(viii) SELECT CneeID, CneeName FROM Consignee WHERE CnorID = ‘MU15’ OR CnorID = ‘ND01’;
senderCity
New Delhi
Mumbai
Ans:
CneeID CneeName
MU05 Rahul
KO19 A P Roy Kishore
Q4. Consider the following tables. Write SQL command for the statements (i)to(iv)and give outputs for the SQL quries (v)
to (viii).
TABLE : SENDER
Sender Sender
SenderID SenderName
Address City
ND01 R jain 2,ABC Appts New Delhi
MU02 H sinha 12, Newton Mumbai
27/ A,Park
MU1 5 S haj New Delhi
Street
ND5 0 T Prasad 122-K,SDA Mumbai
TABLE :RECIPIENT
(ii) To display the recID, senderName, senderAddress, RecName, RecAddress for every recipt.
Ans: Select recID, SenderName, SenderAddress, RecName, RecAddress from Sender, Recipient where
Sender.Senderid=Recipient.RenderId;
Ans:
Sender
City
New Delhi
Mumbai
(vi) SELECT A.SenderName A, B.RecName FROM Sender A, Recipient B WHERE A.SenderID=B. SenderID AND
B.RecCity=’Mumbai’;
Ans:
SenderName RecName
R.Jain H.Singh
S.Jha P.K.Swamy
Ans:
RecName RecAddressS
Mahajan 116,A Vihar
S Tripati 13, B1 D, Mayur Vihar
(viii) SELECT RecID, RecName FROM Recipient WHERE SenderID = ‘MU02’ OR SenderID = ‘ND50’;
Ans:
RecID RecName
ND08 S Mahajan
ND48 S Tripathi
Q5. Study the following tables FLIGHTS and FARES and write SQL commands for the questions (i) to (iv).
TABLE: FLIGHTS
NO_ NO_
FL_NO STARTING ENDING
FLGHTS STOPS
IC301 MUMBAI DELHI 8 0
IC799 BANGALORE DELHI 2 1
MC101 INDORE MUMBAI 3 0
IC302 DELHI MUMBAI 8 0
AM812 KANPUR BANGLORE 3 1
IC899 MUMBAI KOCHI 1 4
AM501 DELHI TRIVENDRUM 1 5
MU499 MUMBAI MADRAS 3 3
IC701 DELHI AHMEDABAD 4 0
TABLE:FLIGHTS
(i) Display FL_NO and NO_FLIGHTS from “KANPUR” TO “BANGALORE” from the table FLIGHTS.
Ans: Select FL_NO, NO_FLIGHTS from FLIGHTS where Starting=”KANPUR” AND ENDING=”BANGALORE”;
(ii) Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
(iii) Display the FL_NO and fare to be paid for the flights from DELHI to MUMBAI using the tables FLIGHTS and
FARES, where the fare to paid = FARE+FARE+TAX%/100.
Ans: Select FL_NO, FARE+FARE+(TAX%/100) from FLIGHTS, FARES where Starting=”DELHI” AND
Ending=”MUMBAI”;
(iv) Display the minimum fare “Indian Airlines” is offering from the tables FARES.
Q6. Study the following tables DOCTOR and SALARY and write SQL commands for the questions (i) to (iv) and give
outputs for SQL queries (v) to (vi) :
TABLE: DOCTOR
ID NAME DEPT SEX EXPERIENCE
101 Johan ENT M 12
104 Smith ORTHOPEDIC M 5
107 George CARDIOLOGY M 10
114 Lara SKIN F 3
K
109 MEDICINE F 9
George
105 Johnson ORTHOPEDIC M 10
117 Lucy ENT F 3
111 Bill MEDICINE F 12
130 Murphy ORTHOPEDIC M 15
TABLE: SALARY
(i) Display NAME of all doctors who are in “MEDICINE” having more than 10 years experience from the Table DOCTOR.
(ii) Display the average salary of all doctors working in “ENT”department using the tables. DOCTORS and SALARY Salary
=BASIC+ALLOWANCE.
(iv) Display the highest consultation fee among all male doctors.
Ans: 4
(vi) SELECT NAME, DEPT , BASIC from DOCTOR, SALRY Where DEPT = “ENT” AND DOCTOR.ID = SALARY.ID
Ans:
Name Dept Basic
Jonah Ent 12000
Q7. Consider the following tables EMPLOYEES and EMPSALARY. write SQL commands for the Statements (i) to (iv)
and give outputs for SQL quires (v) to (viii).
EMPSALRAY
(i) To display Firstname, Lastname, Address and City of all employees living in Paris from the table EMPLOYEES.
(iv) To display the Maximum salary among Managers and Clerks from the table EMPSALARY.
Ans:
Firstname Salary
Rachel 32000
Peter 28000
Ans: 4
(vii) SELECT DESIGNATION , SUM(SALARY) FROM EMPSALARY GROUP BY DESIGNATION HAVING COUNT(*)>2;
Ans:
Designation Sum(Salary)
Manager 215000
Clerk 135000
Ans: 32000
Q8. Consider the following tables WORKERS and DESIG. Write SQL commands for the statements (i) to (iv) and give
outputs for SQL queries (v) to (viii).
WORKERS
DESIG
DESIGINA
W_ID SALARY BENEFITS
TION
102 75000 15000 Manager
105 85000 25000 Director
144 70000 15000 Manager
210 75000 12500 Manager
255 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
451 28000 7500 Salesman
(i) To display W_ID Firstname, address andCity of all employees living in New York fromthe Table WORKERs
(iii) To display the FIRSTNAME, LASTNAME and Total Salary of all Clerks from the tables WORKERS And DESIG,
where Total salary is calculated as Salary + benifts.
(iv) To display the minimum salary among managers and Clerks from the tables DESIG.
(v) SELECT FIRSTNAME, SALARY FROM WORKERS, DESIG WHERE DESIGINATION = “MANAGER” AND
WORKERS.W_ID = DESIGN.W_ID
Ans:
FIRSTNAME SALARY
Sam 75000
Manila 70000
George 75000
Ans: 4
(vii) SELECT DESIGNATION, SUM(SALARY) FROM DESIG GROUP BY DESIGNATION HAVING COUNT (*) < 3;
Ans:
Designation Sum(Salary)
Director 85000
Salesman 60000
Ans: 15000
TABLE:ISSUED
BOOK_ID QUANTITY_ISSUED
F0001 3
T0001 1
C0001 5
Write SQL queries from b to g.
(i)To show Book name, Author name and Price of books of EPB publisher.
(iii) To display the names and prices of the books in descending order of their price.
Ans: update books set price= price+50 where publishers = “First Publ”;
(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: “F0002”,4
(vii) Give the output of the following queries on the above tables:
Ans: 3
Ans: 1350.
Ans: Book_Name Author_Name My First PYTHON Brian & Brooks PYTHON Brainworks A.W.Rossaine Fast Cook Lata
Kapoor.
Ans: 5
Q10. Write SQL commands for (b) to (g) and write the outputs for (h) on the basis of tables TNTERIORS and NEWONES.
TABLE: INTERIORS
ITEM
NO TYPE DATEOFSTOCK PRICE DISCOUNT
NAME
1 Red rose DoubleBed 23/02/02 32000 15
2 Soft touch Baby cot 20/01/02 9000 10
3 Jerry’shome Baby cot 19/02/02 8500 10
Rough
4 Office Table 01/01/02 20000 20
wood
Comfort
5 Double Bed 12/01/02 15000 20
zone
6 Jerry look Baby cot 24/02/02 7000 19
7 Lion king Office Table 20/02/02 16000 20
8 Royal tiger Sofa 22/02/02 30000 25
9 Park sitting Sofa 13/12/01 9000 15
Dine
10 DinningTable 19/02/02 11000 15
paradise
TABLE:NEWONES
(i) To show all information about the sofas from the INTERIORS table.
(ii) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from the INTERIORS
table in descending order of ITEMNAME.
(iii) To display ITEMNAME and DATEOFSTOCK of those items in which the Discount percentage is more than 15 from
INTERIORS.
(v) To insert new row in the NEWONES table with the following data:14, “True Indian “, “Office Table “,
{28/03/03},15000,20.
Ans: 5
Ans: 13