You are on page 1of 3

Practical File (SQL)

1. Write SQL commands for (a) to (f) and write the output of (g) on the basis of table HOSPITAL:
Table: HOSPITAL

No Name Age Department Dateofadm Charges Sex


1. Sandeep 65 Surgery 23/02/98 300 M
2. Ravina 24 ENT 20/01/98 200 F
3. Karan 45 Orthopedic 19/02/98 200 M
4. Tarun 12 Surgery 01/01/98 300 M
5. Zubin 36 ENT 12/01/98 250 M
6. Ketika 16 ENT 24/02/98 250 F
7. Ankita 29 Cardiology 20/02/98 800 F
8. Zareen 45 Gynecology 22/02/98 300 F
9. Kush 19 Cardiology 13/01/98 800 M
10. Shailya 31 Nuclear Medicine 19/02/98 400 M

(a) To show all the information of patients of cardiology department.


(b) To list the names of female patients who are in orthopaedic department.
(c) To list names of all patients with their date of admission in ascending order.
(d) To display patient’s name, charges, age for only male patients.
(e) To count the number of patients with Age > 20.
(f) To insert a new row in Hospital table with the following data:
11, ‘Mustafa’, 37, ‘ENT’, {25/02/98}, 250, ‘M’
(g) Give the output of following statements:
i. SELECT COUNT(DISTINCT Department) FROM Hospital;
ii. SELECT MAX(Age) FROM Hospital WHERE Sex = ‘M’;
iii. SELECT AVG(Charges) FROM Hospital WHERE Sex = ‘F’;
iv. SELECT SUM(Charges) FROM Hospital WHERE Dateofadm < {12/02/1998};

2. Write SQL commands for (a) to (e) and write the output of (f) on the basis of table CLUB:
Table: CLUB

Mcode Mname Sex Age Fees Type


1 Pratyush Male 45 24000 Yearly
2 Deepak Male 35 8000 Monthly
3 Gitika Female 22 7000 Monthly
4 Pallavi Female 27 12000 Quarterly
5 Varun Male 54 6000 Monthly
6 Prerna Female 43 4500 Monthly
7 Farida Female 22 500 Guest
8 Jatin Male 51 24000 Yearly
9 Rakshit Male 44 100000 Life
10 Harshit Male 32 13000 Quarterly

(a) To display Mname, Age, Fees of those members of CLUB whose fees is between 5000 and
11000.
(b) To display Mcode, Mname, Age of all female members of the CLUB with age in descending
order.
(c) To display Mname, Age, Type of members of the CLUB with Mname in ascending order.
(d) To display Mname, Fees of all those members of the CLUB whose Age < 40 and are Monthly
type members of the CLUB.
(e) To get a new tuple in the table CLUB with following data:
11, ‘Vaibhav’, ‘Male’, 31, 900, ‘Guest’
(f) Write the output of following statements:
i. SELECT MAX(Fees) FROM Club;
ii. SELECT SUM(Fees) FROM Club WHERE Age > 35;
iii. SELECT AVG(Age) FROM CLUB WHERE Type = ‘Monthly’;

3. Write SQL commands for (a) to (f) and write the output of (g) on the basis of table LAB:
Table: CLUB

No ItemName CostPerItem Quantity DateOfPurchase Warranty Operating


1 Computer 60000 9 21/05/96 2 7
2 Printer 15000 3 21/05/97 4 2
3 Scanner 18000 1 29/08/98 3 1
4 Camera 21000 2 13/06/96 1 2
5 Hub 8000 4 31/10/99 2 1
6 UPS 5000 5 21/05/96 1 4
7 Plotter 25000 2 11/01/2000 2 2

(a) To select item name purchased after 31/05/97.


(b) To list the item name, which are, within the warranty period till present date.
(c) To list the item name in ascending order of the date of purchase where quantity is more than
3.
(d) To display item name, Cost Per Item and Quantity whose warranty is over.
(e) To count the number of items whose cost is more than 10000.
(f) To insert a new record in the LAB table with following data:
8, ‘VCR’, 10000, 2, {2/2/2000}, 1, 2
(g) Give the output of following statements:
i. SELECT MIN(DISTINCT Quantity) FROM Lab;
ii. SELECT MIN(Warranty) FROM Lab WHERE Quantity = 2;
iii. SELECT SUM(CostPerItem)FROM Lab WHERE Quantity > 7;
iv. SELECT AVG(CostPerItem) FROM Lab WHERE DatOfPurchase < {01/01/99};

4. Write SQL commands for (a) to (f) and write the output of (g) on the basis of table LAB:
Table: SHOP

No Shop_Name Sale Area Cust_Percent Rating City


1 S.M. Sons 250000 West 68.6 C Delhi
2 Dharohar 500000 South 81.8 A Mumbai
3 Kriti Art 300000 North 79.8 B Kolkata
4 Ripple 380000 North 88.0 B Mumbai
5 Biswas Stores 456000 East 92.0 A Delhi
6 Crystal 290000 South 66.7 A Kolkata

(a) To display the names of all shops which are in the area SOUTH.
(b) To display name and customer percentage of all shops having Cust_Percent > 80.
(c) To display list of all shops with sale > 300000 in ascending order of Shop_Name.
(d) To display a report with Shop_Name, Area, and Rating for each shop in the table, for only
those shops whose sale is between 350000 and 400000 (both inclusive).
(e) To display the city and number of shops in each city in the table SHOP.
(f) To insert details of new shop with the following data:
7, ‘The Shop’, 550000, ‘South’, 90.8, ‘A’, ‘Ahmedabad’
(g) Write the output of following statements.
i. SELECT MIN(Cust_Percent) FROM Shop;
ii. SELECT SUM(Sale) FROM Shop WHERE Rating = ‘A’;
iii. SELECT AVG(Sale) FROM Shop WHERE City = ‘Delhi’;
iv. SELECT COUNT(DISTINCT City) FROM Shop;

5. In a database create the following tables with suitable constraints. Based on these tables write SQL
statements for the following queries:
Table: ITEMS

I_Code Name Category Rate


1001 Masala Dosa South Indian 60
1002 Vada Sambhar South Indian 40
1003 Idli Sambhar South Indian 40
2001 Chow Mein Chinese 80
2002 Dimsum Chinese 60
2003 Soup Chinese 50
3001 Pizza Italian 240
3002 Pasta Italian 125

Table: BILLS

BillNo Date I_Code Qty


1 2010-04-01 1002 2
1 2010-04-01 3001 1
2 2010-04-01 1001 3
2 2010-04-01 1002 1
2 2010-04-01 2003 2
3 2010-04-02 2002 1
4 2010-04-02 2002 4
4 2010-04-02 2003 2
5 2010-04-03 2003 2
5 2010-04-03 3001 1
5 2010-04-03 3002 3

(a) Display the average rate of a South Indian item.


(b) Display the number of items in each category.
(c) Display the total quantity sold for each item.
(d) Display total quantity of each item sold but don’t display this data for the items whose total
quantity sold is less than 3.
(e) Display the details of bill records along with name of each corresponding item.
(f) Display the details of the bills records for which the item is ‘Dosa’.
(g) Display the bill records for each Italian item sold.
(h) Display the total value of items sold for each bill.

You might also like