SQL Practical-Question Paper

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Practical No 2: CUSTOMER AND ITEM TABLE AND QUERIES

Write MYSQL commands for the following


i) Identify primary keys in the table and foreign key in CUSTOMER table given
above.

ii) To display the customer name, city from table customer and item name and
price from table item with their corresponding matching I_ID.

iii) To display the customer name and price from Delhi customers who uses the
items whose price is more than 50000.

iv) List the items details whose price between 35000 and 50000.

v) SELECT Customername,manufacturer
From item, customer
Where item.I_ID = customer.I_ID;
vi) SELECT Itemname,price*100, customername
From item,customer
Where manufacturer= ‘ABC’ and item.I_ID = customer.I_ID;
Practical No 2: SENDER AND RECIPIENT TABLE AND QUERIES

Write MYSQL commands for the following.

i) Identify Primary Keys in the table and foreign key in recipient table given
above.

ii) To display the name of all senders along with the name of receiver from
Mumbai.

iii) To display the recid, sendername, senderaddress, recname, recaddress for


every recipient.

iv) To display recipient details along with the sender name in ascending order of
recname.

v) Select A.sendername,B.recname from sender A, recipient B


Where A.senderid= B.senderid and B.reccity = ‘Mumbai’;

vi) Select recid,recnamefrom recipient


Where senderid=’MU02’ or senderid=’ND50’;
Practical No 2: DOCTOR AND SALARY TABLE AND QUERIES

Write MYSQL commands for the following

i) Identify Primary key in the table given above.

ii) Display names of all doctors who are in “MEDICINE” having more than 10
years’ experience and basic salary more than 10000.

iii) Display the average of all the Doctors working in “ENT” department using the
table DOCTOR and (SALARY.salary = BASIC + ALLOWANCES)

iv) Display the minimum ALLOWANCE of female doctors.

v) Display the highest consultation fee among all male doctors.

vi) SELECT NAME, DEPT,BASIC from DOCTOR , SALARY


Where DEPT=’ENT’ AND DOCTOR.ID = SALARY.ID;
Practical No 2: PRODUCT AND CLIENT TABLE AND QUERIES

Write MY SQL commands for the following

i) Identify primary keys in the table and the foreign key in the CLIENT table
given above.

ii) To display client name, city, from table CLIENT and Product name and Price
from table Product with their corresponding matching P_ID.

iii) To display all the details of DELHI Clients.

iv) To display the Client names and Product names who uses the product price
between 50 and 100.

v) Select Client_name, manufacturer, from product, client


Where Client.P_ID =Product.P_ID ;

vi) Select Client_name, Product_name from Product, Client


where Client.P_ID = Product.P_ID and Price > 50;
Practical No 2: - Table: TEACHER

Write the SQL command for (a) to (f) and write the output for the (g) on the basis of
table Teacher.

(a) To show all information about the teacher of History department.

(b) To list the name of female teachers who are in math’s department.

(c) To list names of all the teachers along with their date of joining in
ascending order.

(d) To display teachers name, salary, age for male teacher only.

(e) To count the number of teacher with age > 23.

(f) To insert row in the table with the following data


9,’Raja’,26,’Computer’,’1995-05-13’,23000,’m’.

(g) Give the output of the following SQL commands


a. SELECT COUNT(DISTINCE department) FROM TEACHER;
b. SELECT MAX(Age) FROM TEACHER WHERE GENDER=’F’;
c. SELECT AVG(Salary) FROM TECAHER WHERE GENDER=’M’;
d. SELECT SUM(Salary) FROM TEACHER WHERE
DATE_OFF_OINING<’1996-07-12’;
Practical No 2: Table- GRADUATE
Write the SQL command for (a) to (d) and write the output for the (e) on the
basis of table Teacher

(a) List the name of those students who have obtained div1 = 1 sorted by
name

(b) Display the report listing name,, stipend, subject and amount of stipend
received in a year assuming that the stipend is paid every month.

(c) To count the number of student who are either PHYSICS or COMPUTER SC
graduate.

(d) To insert a new row in the graduate table


11,’KAJOL’, 300,’COMPUTER SCI’, 75, 1

(e) Give the output of the following SQL statement based on table
GRADUATE
a. SELECT MIN(AVERAGE) FROM GRADUATE WHERE SUBJECT =
‘PHYSICS’;
b. SELECT SUM(STIPEND FROM GRADUATE WHERE DIV1 = 2;
c. SELECT AVG(STIPEND) FROM GRADUATE WHERE AVERAGE> =65;
d. SELECT COUNT(DISTINCE SUBJECT) FROM GRADUATE;
Practical No 2: Table- BANK
Write the SQL command for (a) to (F) and write the output for the (G) on the
basis of table BANK

(a) Display data for all the customers whose transaction is between 8 and 11.
(b) Display data for all customers sorted by their date of open.
(c) To count the number of customers with amount<30000.
(d) List minimum and maximum amount from the bank
(e) To list cname, bname, amount for all the clients whose amount is <20000.
(f) To display acc_no, cname, bname, total transactions in descending order of
amount.
(g) Give the output of the following sql commands
a. SELECT AVG(AMOUNT) FROM BANK WHERE AMOUNT < 23000.

b. SELECT MAX(AMOUNT) FROM BANK WHERE AMOUNT>30000.

c. SELECT SUM(T_TRANSACTIONS) FROM BANK;

d. SELECT COUNT(DISTINCT BNAME) FROM BANK;


Practical No 2: Table- FAMILY

Write the SQL command for (a) to (F) and write the output for the (G) on the

basis of table FAMILY

(a) To select all the information of family whose occupation is service?


(b) To list the names of family where female members are more thane3.
(c) To list all names of family with income in ascending order.
(d) To display family’s name, male members and occupation of business family.
(e) To count number of families whose income is less than 10000.
(f) To insert a new record in the family table with the following data
9,’Dsouza’, 2, 1, 15000, ’Service’;
(g) Give output of following commands
a. SELECT MIN(DISTINCT INCOME) FROM FAMILY;
b. SELECT MIN(FEMALEMEMBERS) FROM FAMILY WHERE
OCCUPATION=’MIXED’;
c. SELECT SUM(INCOME) FROM FAMILY WHERE
OCCUPATION=’SERVICE’;SELECT AVG(INCOME) FROM FAMILY;
Practical No 2: - Table- FLIGHT
Write the SQL command for (a) to (F) and write the output for the (G) on the
basis of table FLIGHT

(a) To display the flight number of those flights which have frequency more than 4
times in a week;
(b) To display flightno, from city and to city of all those flight which are starting from
city blue islands or are having destination as blue islands.
(c) To display flightno and seating capacity of all those flights in which seating capacity
is more than 140.
(d) To display flightno, frequency and distance of all those flights, which are covering
distance more than 900 km.

( e) To display flightno all those flights which are weekly flights and having seating
capacity less than 180.

(F) To insert a new flight detail in the table

9,’T1618’,’Mumsui’,Blue Island’,1200 210,4


INSERT INTO FLIGHT VALUES (9,’T1618’,’Mumsui’,Blue Island’,1200 210,4)

(f) Write output


a. SELECT COUNT(*) FROM FLIGHT;
b. SELECT MAX(DISTANCE) FROM FLIGHT;
c. SELECT MIN(FREQUENCY) FROM FLIGHT;
d. SELECT COUNT(DISTINCT FROMCITY) FROM FLIGHT;
Practical No 2: - Table- LIBRARY

Write the SQL command for (a) TO (F) AND WRITE OUTPUT FOR (g)

(a) To display the title of all the books with price between 100 and 300.

(b) To display title and author of all the books having type prog and publisher BPB.

(c) To display the list of all the books with price more than 130 in ascending order of
qty.
(d) To display report with title. Misplacement charges(1.25 of price) for each book in
the table

(e) To display the publisher and the number of books of each publisher in the table
library
(f) To insert a new book in the table library with the following data
11,’Comp sci’,’Reeta’,’C++’,Rachana Sagar’1,225

(g) Find output


a. SELECT MIN(PRICE) FROM LIBRARY;
b. SELECT SUM(PRICE * QUANTITY) FROM LIBRARY WHERE QUANTITY>3;
c. SELECT AVG(PRICE) FROM LIBRARY WHERE QUANTITY < 4;
d. SELECT COUNT(DISTINCT PUBLISHER ) FROM LIBRARY;

You might also like