SQL 1-5 Practical
SQL 1-5 Practical
Part-I [Mysql]
Q1.Consider the following tables GAMES and PLAYER. Write SQL commands for the statements (i) to
(iv) and Give outputs for SQL queries (v) to (viii). [pract-1]
Table:GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 CaromBoard 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 TableTennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 LawnTennis 4 25000 19-Mar-2004
Table:PLAYER
PCode Name Gcode
1 NabiAhmad 101
2 RaviSahai 108
3 Jatin 101
4 Nazneen 103
(i) To display the name of all Games with their Gcodes.
(ii) To display details of those games which are having Prize Money more than 7000.
(iii) To display the content of the GAMES table in ascending order of Schedule Date.
(iv) To display sum of Prize Money for each of the Number of participation groupings (as shown
in column Number 2 or 4)
(v) SELECT COUNT(DISTINCT Number) FROM GAMES;
(vi) SELECT MAX(Schedule Date), MIN(Schedule Date) FROM GAMES;
(vii) SELECTSUM(PrizeMoney) FROM GAMES;
(viii) SELECT DISTINCT Gcode FROM PLAYER;
Q2.Consider the following tables FACULTY and COURSES. Write SQL commands for the statements (i)
to (iv) and give outputs for SQL queries (v) to (vi). [pract-2]
FACULTY
F_ID Fname Lname Hire_date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
COURSES
C_ID F_ID Cname Fees
C21 102 GridComputing 40000
C22 106 SystemDesign 16000
C23 104 ComputerSecurity 8000
C24 106 HumanBiology 15000
C25 102 ComputerNetwork 20000
C26 105 VisualBasic 6000
i) To display details of those Faculties whose salary is greater than 12000.
ii) To display the details of courses whose fees is in the range of 15000 to 50000 (both values
included).
iii) To display details of those courses which are taught by ‘Sulekha’ in descending order of
courses?
iv) Select COUNT(DISTINCT F_ID) from COURSES;
v) Select Fname, Cname from FACULTY, COURSE where COURSE.F_ID=FACULTY.F.ID;
Q3. Write SQL Command for (a) to (d) and output of (e) [pract-3]
TABLE:GRADUATE
S.NO NAME STIPEND SUBJECT AVERAGE DIV
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMPSc 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CHEMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMPSc 62 I
10 VIKAS 400 MATHS 57 II
a. List the names of those students who have obtained DIV I sorted by NAME.
b. Display listing NAME, STIPEND, SUBJECT and amount of stipend received in a year assumming
that the STIPEND is paid every month.
c. To count the number of students who are either PHYSICS or COMPUTERSC graduates.
d. To insert a new row in the GRADUATE table: 11,”KAJOL” ,300, “computersc”, 75 ,1
e. Give the output of following sql statement based on table GRADUATE:
(i) Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”;
(ii) Select SUM(STIPEND) from GRADUATE WHERE div=2;
(iii) Select AVG(STIPEND) from GRADUATE where AVERAGE >= 65;
(iv) Select COUNT(distinctSUBJECT) from GRADUATE;
Q4. Consider the following tables Sender and Recipient. Write SQL commands for the statements
(i) to (iv) and give the outputs for SQL queries (v) to (viii). [pract-4]
Sender
SenderID SenderName SenderAddress Sendercity
ND01 RJain 2,ABCAppls NewDelhi
MU02 H Sinha 12Newtown Mumbai
MU15 S Jha 27/A,ParkStreet Mumbai
ND50 TPrasad 122-K,SDA NewDelhi
Recipients
RecID SenderID RecName RecAddress recCity
KO05 ND01 RBajpayee 5,CentralAvenue Kolkata
ND08 MU02 SMahajan 116,A-Vihar NewDelhi
MU19 ND01 HSingh 2A,AndheriEast Mumbai
MU32 MU15 PKSwamy B5,CSTerminals Mumbai
ND48 ND50 STripathi 13,BIDMayurVihar Newdelhi
a. To display the names of all Senders from Mumbai
b. To display the RecID, Sendername, SenderAddress, RecName, RecAddress for every Recipient
c. To display Recipient details in ascending order of RecName
d. To display number of Recipients from each city
e. SELECT DISTINCTSender City from Sender;
f. SELECT A.SenderName, B.RecName From Sender A, Recipient B Where
A. SenderID =B.SenderID AND B.RecCity=’Mumbai’;
g. SELECT RecName, RecAddress From Recipient Where
RecCity NOTIN(‘Mumbai’,‘Kolkata’);
h. SELECT RecID, RecName FROM Recipent Where SenderID=’MU02’ or SenderID=’ND50’;
Q5 Write SQL queries for (i)to (iv)and find outputs for SQL queries (v) to (viii), which are based
on the tables .[pract-5]
TRAINER
TID TNAME CITY HIREDATE SALARY
101 SUNAINA MUMBAI 1998-10-15 90000
102 ANAMIKA DELHI 1994-12-24 80000
103 DEEPTI CHANDIGARG 2001-12-21 82000
104 MEENAKSHI DELHI 2002-12-25 78000
105 RICHA MUMBAI 1996-01-12 95000
106 MANIPRABHA CHENNAI 2001-12-12 69000
COURSE
CID CNAME FEES STARTDATE TID
C201 AGDCA 12000 2018-07-02 101
C202 ADCA 15000 2018-07-15 103
C203 DCA 10000 2018-10-01 102
C204 DDTP 9000 2018-09-15 104
C205 DHN 20000 2018-08-01 101
C206 OLEVEL 18000 2018-07-25 105
(i) Display the Trainer Name , City &Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of
December 2001.
(iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and COURSE
of all those courses whose FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
(v) SELECT TID,TNAME, FROM TRAINER WHERE CITY NOTIN(‘DELHI’,‘MUMBAI’);
(vi) SELECT DISTINCT TID FROM COURSE;
(vii) SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY TID HAVING
COUNT(*) >1;
(viii) SELECT COUNT(*), SUM(FEES) FROM COURSE WHERE STARTDATE < ‘2018-09-15’;