SQL Tables
SQL Tables
Question 1:
Write SQL commands for the following on the basis given table CLUB:
TABLE: CLUB
COACH_ID COACHNAME AGE SPORTS DATOFAPP PAY SEX
1 KUKREJA 35 KARATE 1996-03-27 1000 M
2 RAVINA 34 KARATE 1998-01-20 1200 F
3 KARAN 34 SQUASH 1998-02-19 2000 M
4 TARUN 33 BASKETBALL 1998-01-01 1500 M
5 ZUBIN 36 SWIMMING 1998-01-12 750 M
6 KETAKI 36 SWIMMING 1998-02-24 800 F
7 ANKITA 39 SQUASH 1998-02-20 2200 F
8 ZAREEN 37 KARATE 1998-02-22 1100 F
9 KUSH 41 SWIMMING 1998-01-13 900 M
10 SHAILYA 37 BASKETBALL 1998-02-19 1700 M
a) To show all information about the swimming coaches in the club.
Answer: SELECT * FROM CLUB WHERE SPORTS = ‘SWIMMING’;
b) To list names of all coaches with their date of appointment (DATOFAPP) in descending order.
Answer: SELECT COACHNAME FROM CLUB ORDER BY DATEOFAPP DESC;
c) To display a report, showing coachname, pay, age and bonus (15% of pay) for all coaches.
Answer: SELECT COACHNAME, PAY, AGE, PAY*15/100 AS BONUS FROM CLUB;
Question 2:
Write SQL commands for the following on the basis of given table STUDENT.
TABLE: STUDENT
No. Name Stipend Stream AvgMark Grade Class
1 Karan 400 Medical 78.5 B 12B
2 Divakar 450 Commerce 89.2 A 11C
3 Divya 300 Commerce 68.6 C 12C
4 Arun 350 Humanities 73.1 B 12C
5 Sabina 500 Nonmedical 90.6 A 11A
6 John 400 Medical 75.4 B 12B
7 Robert 250 Humanities 64.4 C 11A
8 Rubina 450 Nonmedical 88.5 A 12A
9 Vikas 500 Nonmedical 92.0 A 12A
10 Mohan 300 Commerce 67.5 C 12C
a) Select all the nonmedical stream students from STUDENT.
Answer: SELECT * FROM STUDENT WHERE STREAM = ‘Nonmedical’;
b) List the names of those students who are in class 12 sorted by Stipend.
Answer: SELECT * FROM STUDENT WHERE CLASS LIKE '%2%' ORDER BY STIPEND;
c) List all students sorted by AvgMark in descending order.
Answer: SELECT * FROM STUDENT ORDER BY AVGMARK DESC;
d) Display a report, listing Name, Stipend, Stream and amount of stipend received in a year assuming that
the Stipend is paid every month.
Answer: SELECT NAME, STIPEND, STREAM, STIPEND*12 AS STIPEND_PA FROM STUDENT;
Questions 3:
Write SQL commands for the following on the basis of given table:
TABLE: LIBRARY
No. Title Author Type Pub Qty Price
1 Data Structures Lipschutz DS McGraw 4 217
2 Computer Studies French FND Galgotia 2 75
3 Advanced Pascal Schildt PROG McGraw 4 350
4 Dbase dummies Palmer DBMS PustakM 5 130
5 Master C++ Gurewich PROG BPB 3 295
6 Guide Network Freed NET ZPress 3 200
7 Mastering Foxpro Seigal DBMS BPB 2 135
8 DOS Guide Norton OS PHI 3 175
9 Basic for beginners Morton PROG BPB 3 40
10 Mastering Window Cowart OS BPB 1 225
a) Select all the PROG type published by BPB from Library.
Answer: SELECT * FROM LIBRARY WHERE TYPE = ‘PROG’ AND PUB = ‘BPB’;
b) Display a list of all the books with price more than 130 and sorted by Qty.
Answer: SELECT * FROM LIBRARY WHERE PRICE > 130 ORDER BY QTY;
c) Display all the books sorted by Price in ascending order.
Answer: SELECT TITLE FROM LIBRARY ORDER BY PRICE;
Question 4:
Write SQL commands for the following on the basis of the given table GRADUATE:
TABLE: GRADUATE
SNO NAME STIPEND SUBJECT AVERAGE Ranking
1 KARAN 400 PHYSICS 68 1
2 DIVAKAR 450 COMPUTER SC 68 1
3 DIVYA 300 CHEMISTRY 62 2
4 ARUN 350 PHYSICS 63 1
5 SABINA 500 MATHEMATICS 70 1
6 JOHN 400 CHEMISTRY 55 2
7 ROBERT 250 PHYSICS 64 1
8 RUBINA 450 MATHEMATICS 68 1
9 VIKAS 500 COMPUTER SC 62 1
10 MOHAN 300 MATHEMATICS 57 2
a) List the names of those students who have obtained Ranking 1 sorted by NAME.
Answer: SELECT NAME FROM GRADUATE WHERE RANKING = 1 ORDER BY NAME;
b) Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month.
Answer: SELECT NAME, STIPEND, SUBJECT, STIPEND*12 AS 'STIPEND IN A YEAR' FROM
GRADUATE;
Question 5:
Write SQL commands for the following on the basis of given table Teacher:
TABLE: TEACHER
No. Name Age Department Dateofjoin Salary Sex
1 Jugal 34 Computer 1997-01-10 12000 M
2 Sharmila 31 History 1998-03-24 20000 F
3 Sandeep 32 Maths 1996-12-12 30000 M
4 Sangeeta 35 History 1999-07-01 40000 F
5 Rakesh 42 Maths 1997-09-05 25000 M
6 Shyam 50 History 1998-06-27 30000 M
7 Shiv Om 44 Computer 1997-02-25 21000 M
8 Shalakha 33 Maths 1997-07-31 20000 F
a) To show all information about the teacher of history department.
Answer: SELECT * FROM TEACHER WHERE DEPARTMENT='HISTORY';
b) To list the names of female teachers who are in Hindi department.
Answer: SELECT NAME FROM TEACHER WHERE DEPARTMENT='HINDI' AND SEX='F';
c) To list names of all teachers with their date of joining in ascending order.
Answer: SELECT NAME, DATEOFJOIN FROM TEACHER ORDER BY DATEOFJOIN;