Professional Documents
Culture Documents
Submitted By: Zain Saleem Roll No.: F18BA138 Section: Afternoon A' Subject: Database Management System Submitted To: Sir Saleem Raza
Submitted By: Zain Saleem Roll No.: F18BA138 Section: Afternoon A' Subject: Database Management System Submitted To: Sir Saleem Raza
Saleem
Question No 01. 30
Following is the Relational Schema of Course Registration Systems of an institute
Degree(DCode, Title, DCH, Sem)
Students(RegNo, Name, Gender, DoB, City, DCode)
Courses(CCode, CTitle, CH, Sem, DCode)
Faculty(FCode, Name, Designation, eMail, City)
Term(TCode, Description, MidWeek, FinalWeek)
CRS(RegNo, CCode, TCode, OM, Grade)
Teach(FCode, CCode, TCode, Section, FB, NoS) // FB-> Feedback, NoS-? No. of Students
Write the SQL Statements for followings:
i. List the Courses which are not offered in term ‘S15’ but were offered in ‘S14’ 5
SELECT CCode
FROM CRS
WHERE TCode='S14' AND CCode NOT IN
(SELECT CCode
FROM CRS
WHERE TCode='S15');
ii. List the Courses which are not taught by any Faculty in ‘S15’ 5
SELECT CCode
FROM Teach
WHERE CCode NOT IN
(SELECT CCode
FROM Teach
WHERE TCode='S15');
iii. List Faculty who has taught ‘BF-357’ and ‘EC-123’ but have NEVER taught ‘CS-137’ 5
SELECT FCode
FROM Teach
WHERE CCode='BF-357' OR CCode='EC-123' AND FCode NOT IN
(SELECT FCode
FROM Teach
WHERE CCode='CS-137');
SELECT CCode
FROM Faculty INNER JOIN Teach ON Faculty.FCode=Teach.FCode
WHERE Designation='Lecturer' AND TCode='S17' AND CCode IN
(SELECT CCode
FROM Faculty INNER JOIN Teach ON Faculty.FCode=Teach.FCode
WHERE Designation='Professor' AND TCode='S15');
v. List the Students Name with Course Titles of students who are enrolled only in those courses during
term ‘S17’ in which students have secured ‘A’ in term ‘S15’. 5
vi. List the Students who are enrolled in courses offered in even semesters of the ‘BBIT’ 5
SELECT StdName
FROM Student
WHERE RegNo NOT IN
(SELECT RegNo
FROM IsRegistered
WHERE Term='SP09');
ii. Retrieve the Course Title, Pre-Req Course, and Qualified Faculty Name for all courses. 5
Sample Output of query for the above given state database:
Course Title Pre Requisite Course Qualified Faculty Name
C Programming NULL Sara
Data Structures C Programming Shoaib
Data Structures C Programming Imran
Database Systems Data Structures Imran
Database Systems Data Structures Qadeer
Compiler Construction Data Structures Shoaib
Software Engineering Database Systems NULL
WHERE Company.cCity=Lives.pCity;
b. Find the persons whose salaries are more than the salary of everybody working with company ’SBC’. 4
SELECT pName
FROM Works
WHERE Salary>ALL
(SELECT Salary
FROM Works
WHERE cTitle='SBC');
c. Find the names of the companies which is located-in every city where company ’SBC’ is located-in. 4
SELECT cTitle
FROM Company
WHERE cCity IN
(SELECT cCity
FROM Company
WHERE cTitle='SBC');
d. List names of person along with company who lives in different city than the city of their company 4
SELECT Works.pName, Works.cTitle
FROM (Company INNER JOIN Works ON Company.cTitle=Works.cTitle)
INNER JOIN Lives ON Works.pName=Lives.pName
WHERE Company.cCity<>Lives.pCity;
e. List names of persons, Company City and Salary; who are 2 managerial levels below the person ‘Ali’ 4
SELECT *
FROM (SELECT*
FROM managers
WHERE mName IN
(SELECT pName
FROM managers
WHERE mName IN
(SELECT pName
FROM managers
WHERE pName='Ali')))
Finish Line
Nothing beyond this line will be evaluated