Problem Statement No: 01
Suppliers(sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)
1. Find the names of suppliers who supply some red part.
2. Find the sids of suppliers who supply some red or green part.
3. Find the sids of suppliers who supply some red part or are at 221 Packer Ave.
4. Find the sids of suppliers who supply some red part and some green part.
5. Find the sids of suppliers who supply every part.
6. Find the sids of suppliers who supply every red part.
7. Find the sids of suppliers who supply every red or green part.
8. Find the sids of suppliers who supply every red part or supply every green part.
9. Find pairs of sids such that the supplier with the first sid charges more for some
part than the supplier with the second sid.
10. Find the pids of parts that are supplied by at least two different suppliers.
11. Find the pids of the most expensive parts supplied by suppliers named Yosemite
Sham.
Answers :-
1) SELECT [Link] FROM Suppliers S, Parts P, Catalog C WHERE [Link]=’red’ AND [Link]=[Link] AND
[Link]=[Link]
2) SELECT [Link] FROM Catalog C, Parts P WHERE ([Link] = ‘red’ OR [Link] = ‘green’)
AND [Link] = [Link]
3) SELECT [Link] FROM Suppliers S WHERE [Link] = ‘221 Packer street’ OR [Link] IN ( SELECT [Link]
FROM Parts P, Catalog C WHERE [Link]=’red’ AND [Link] = [Link] )
4) SELECT [Link] FROM Parts P, Catalog C WHERE [Link] = ‘red’ AND [Link] = [Link]
AND EXISTS ( SELECT [Link] FROM Parts P2, Catalog C2
WHERE [Link] = ‘green’ AND [Link] = [Link]
AND [Link] = [Link] )
5) SELECT [Link] FROM Catalog C WHERE NOT EXISTS (SELECT [Link] FROM Parts P WHERE NOT EXISTS
(SELECT [Link] FROM Catalog C1 WHERE [Link] = [Link] AND [Link] = [Link]))
6) SELECT [Link] FROM Catalog C WHERE NOT EXISTS (SELECT [Link] FROM Parts P WHERE [Link] = ‘red’
AND (NOT EXISTS (SELECT [Link] FROM Catalog C1 WHERE [Link] = [Link] AND [Link] = [Link])))
7) SELECT [Link] FROM Catalog C WHERE NOT EXISTS (SELECT [Link] FROM Parts P WHERE ([Link] = ‘red’
OR [Link] = ‘green’) AND (NOT EXISTS (SELECT [Link] FROM Catalog C1 WHERE [Link] = [Link] AND
[Link] = [Link])))
8) SELECT [Link] FROM Catalog C WHERE (NOT EXISTS (SELECT [Link] FROM Parts P WHERE [Link] = ‘red’
AND (NOT EXISTS (SELECT [Link] FROM Catalog C1 WHERE [Link] = [Link] AND [Link] = [Link]))))
9) SELECT [Link], [Link] FROM Catalog C1, Catalog C2 WHERE [Link] = [Link] AND [Link] 6= [Link] AND
[Link] > [Link]
10) SELECT [Link] FROM Catalog C WHERE EXISTS (SELECT [Link] FROM Catalog C1 WHERE [Link] = [Link]
AND [Link] 6= [Link] )
11) SELECT [Link] FROM Catalog C, Suppliers S WHERE [Link] = ‘Yosemite Sham’ AND [Link] = [Link] AND
[Link] ≥ ALL (Select [Link] FROM Catalog C2, Suppliers S2 WHERE [Link] = ‘Yosemite Sham’ AND
[Link] = [Link])
Problem Statement 02
Flights(flno: integer, from: string, to: string, distance: integer, departs: time, arrives: time)
Aircraft(aid: integer, aname: string, cruisingrange: integer)
Certified(eid: integer, aid: integer)
Employees(eid: integer, ename: string, salary: integer)
[Link] the eids of pilots certified for some Boeing aircraft.
2. Find the names of pilots certified for some Boeing aircraft.
3. Find the aids of all aircraft that can be used on non-stop flights from Bonn to Madras.
4. Identify the flights that can be piloted by every pilot whose salary is more than $100,000.
5. Find the names of pilots who can operate planes with a range greater than 3,000 miles but are not
certified on any Boeing aircraft.
6. Find the eids of employees who make the highest salary.
7. Find the eids of employees who make the second highest salary.
8. Find the eids of employees who are certified for the largest number of aircraft.
9. Find the eids of employees who are certified for exactly three aircraft.
10. Find the total amount paid to employees as salaries.
Answers:-
1)SELECT [Link] FROM Aircraft A, Certified C WHERE [Link] = [Link] AND [Link] = ‘Boeing’
2) SELECT [Link] FROM Aircraft A, Certified C, Employees E WHERE [Link] = [Link] AND [Link] =
‘Boeing’ AND [Link] = [Link]
3) SELECT [Link] FROM Aircraft A, Flights F WHERE [Link] = ‘L.A.’ AND [Link] = ‘N.Y.’ AND [Link] >
[Link]
4) SELECT [Link] FROM Aircraft A, Certified C, Employees E, Flights F WHERE [Link] = [Link] AND [Link] =
[Link] AND distance < cruisingrange AND salary > 100,000
5) SELECT [Link] FROM Certified C, Employees E, Aircraft A WHERE [Link] = [Link] AND [Link] = [Link]
AND [Link] > 3000 AND [Link] NOT IN ( SELECT [Link] FROM Certified C2, Aircraft A2 WHERE
[Link] = [Link] AND [Link] = ‘Boeing’ )
6) SELECT [Link] FROM Employees E WHERE [Link] = ( Select MAX ([Link]) FROM Employees E2 )
7) SELECT [Link] FROM Employees E WHERE [Link] = (SELECT MAX ([Link]) FROM Employees E2
WHERE [Link] 6= (SELECT MAX ([Link]) FROM Employees E3 ))
8) SELECT [Link] FROM ( SELECT [Link] AS eid, COUNT ([Link]) AS cnt, FROM Certified C GROUP BY
[Link]) AS Temp WHERE [Link] = ( SELECT MAX ([Link]) FROM Temp)
9) SELECT [Link] FROM Certified C1, Certified C2, Certified C3 WHERE ([Link] = [Link] AND [Link] =
[Link] AND [Link] ≠ [Link] AND [Link] ≠ [Link] AND [Link] ≠ [Link])
10) SELECT SUM ([Link]) FROM Employees E
Problem Statement 03 :-
Student(snum: integer, sname: string, major: string, level: string, age: integer) Class(name: string, meets
at: time, room: string, fid: integer)
Enrolled(snum: integer, cname: string)
Faculty(fid: integer, fname: string, deptid: integer)
1)Find the names of all Juniors (Level = JR) who are enrolled in a class taught by I. Teach.
2. Find the age of the oldest student who is either a History major or is enrolled in a course taught by I.
Teach.
3. Find the names of all classes that either meet in room R128 or have five or more students enrolled.
4. Find the names of all students who are enrolled in two classes that meet at the same time.
5. Find the names of faculty members who teach in every room in which some class is taught.
6. Find the names of faculty members for whom the combined enrollment of the courses that they teach
is less than five.
7. Print the Level and the average age of students for that Level, for each Level.
8. Print the Level and the average age of students for that Level, for all Levels except JR.
9. Find the names of students who are enrolled in the maximum number of classes.
10. Find the names of students who are not enrolled in any class.
Answers :-
1)SELECT DISTINCT [Link] FROM Student S, Class C, Enrolled E, Faculty F WHERE [Link] = [Link] AND
[Link] = [Link] AND [Link] = [Link] AND [Link] = ‘[Link]’ AND [Link] = ‘JR’
2) SELECT MAX([Link]) FROM Student S WHERE ([Link] = ‘History’) OR [Link] IN (SELECT [Link] FROM
Class C, Enrolled E, Faculty F WHERE [Link] = [Link] AND [Link] = [Link] AND [Link] = ‘[Link]’ )
3) SELECT [Link] FROM Class C WHERE [Link] = ‘R128’ OR [Link] IN (SELECT [Link] FROM Enrolled
E GROUP BY [Link] HAVING COUNT (*) >= 5)
4) SELECT DISTINCT [Link] FROM Student S WHERE [Link] IN (SELECT [Link] FROM Enrolled E1,
Enrolled E2, Class C1, Class C2 WHERE [Link] = [Link] AND [Link] <> [Link] AND [Link] =
[Link] AND [Link] = [Link] AND [Link] = [Link])
5) SELECT DISTINCT [Link] FROM Faculty F WHERE NOT EXISTS (( SELECT * FROM Class C ) EXCEPT
([Link] FROM Class C1 WHERE [Link] = [Link] ))
6) SELECT DISTINCT [Link] FROM Faculty F WHERE 5 > (SELECT [Link] FROM Class C, Enrolled E
WHERE [Link] = [Link] AND [Link] = [Link])
7) SELECT [Link], AVG([Link]) FROM Student S GROUP BY [Link]
8) SELECT [Link], AVG([Link]) FROM Student S WHERE [Link] <> ‘JR’ GROUP BY [Link]
9) SELECT DISTINCT [Link] FROM Student S WHERE [Link] IN (SELECT [Link] FROM Enrolled E
GROUP BY [Link] HAVING COUNT (*) >= ALL (SELECT COUNT (*) FROM Enrolled E2 GROUP BY
[Link] ))
10) SELECT DISTINCT [Link] FROM Student S WHERE [Link] NOT IN (SELECT [Link] FROM Enrolled E)
Problem Statement 04 :-
Flights(flno: integer, from: string, to: string, distance: integer, departs: time, arrives: time, price: integer)
Aircraft(aid: integer, aname: string, cruisingrange: integer)
Certified(eid: integer, aid: integer)
Employees(eid: integer, ename: string, salary: integer)
[Link] the names of aircraft such that all pilots certified to operate them earn more than 80,000.
2. For each pilot who is certified for more than three aircraft, find the eid and the maximum
cruisingrange of the aircraft that he (or she) is certified for.
3. Find the names of pilots whose salary is less than the price of the cheapest route from Los Angeles to
Honolulu.
4. For all aircraft with cruisingrange over 1,000 miles, find the name of the aircraft and the average
salary of all pilots certified for this aircraft.
5. Find the names of pilots certified for some Boeing aircraft.
[Link] the aids of all aircraft that can be used on routes from Los Angeles to Chicago.
7. Identify the routes that can be piloted by every pilot who makes more than $100,000.
8. Print the enames of pilots who can operate planes with cruisingrange greater than 3,000 miles, but
are not certified on any Boeing aircraft.
9. A customer wants to travel from Madison to New York with no more than two changes of flight. List
the choice of departure times from Madison if the customer wants to arrive in New York by 6 p.m.
10. Compute the difference between the average salary of a pilot and the average salary of all
employees (including pilots).
Answers:-
1) SELECT DISTINCT [Link] FROM Aircraft A WHERE [Link] IN (SELECT [Link] FROM Certified C,
Employees E WHERE [Link] = [Link] AND NOT EXISTS ( SELECT * FROM Employees E1 WHERE
[Link] = [Link] AND [Link] < 80000 ))
2) SELECT [Link], MAX ([Link]) FROM Certified C, Aircraft A WHERE [Link] = [Link] GROUP BY [Link]
HAVING COUNT (*) > 3
3) SELECT DISTINCT [Link] FROM Employee E WHERE [Link] < ( SELECT MIN ([Link]) FROM Flights F
WHERE [Link] = ‘LA’ AND [Link] = ‘Honolulu’ )
4) SELECT [Link], [Link] FROM ( SELECT [Link], [Link] AS name, AVG ([Link]) AS
AvgSalary FROM Aircraft A, Certified C, Employes E WHERE [Link] = [Link] AND [Link] = [Link] AND
[Link] > 1000 GROUP BY [Link], [Link] ) AS Temp
5) SELECT DISTINCT [Link] FROM Employees E, Certified C, Aircraft A WHERE [Link] = [Link] AND [Link] =
[Link] AND [Link] = ‘Boeing’
6) SELECT [Link] FROM Aircraft A WHERE [Link] > ( SELECT MIN ([Link]) FROM Flights F
WHERE [Link] = ‘L.A.’ AND [Link] = ‘Chicago’ )
7) SELECT DISTINCT [Link], [Link] FROM Flights F WHERE NOT EXISTS ( SELECT * FROM Employees E
WHERE [Link] > 100000 AND NOT EXISTS (SELECT * FROM Aircraft A, Certified C WHERE
[Link] > [Link] AND [Link] = [Link] AND [Link] = [Link]) )
8) SELECT DISTINCT [Link] FROM Employees E, Certified C, Aircraft A WHERE [Link] = [Link] AND [Link] =
[Link] AND [Link] > 3000 AND [Link] NOT IN ( SELECT [Link] FROM Certified C1, Aircraft A1
WHERE [Link] = [Link] AND [Link] = ‘Boeing’ )
9) SELECT [Link] FROM Flights F WHERE [Link] IN ( ( SELECT [Link] FROM Flights F0 WHERE [Link]
= ‘Madison’ AND [Link] = ‘NY’ AND AND [Link] < 1800 ) UNION ( SELECT [Link] FROM Flights F0,
Flights F1 WHERE [Link] = ‘Madison’ AND [Link] <> ‘NY’ AND AND [Link] = [Link] AND [Link] = ‘NY’
[Link] > [Link] AND [Link] < 1800 ) UNION ( SELECT [Link] FROM Flights F0, Flights F1,
Flights F2 WHERE [Link] = ‘Madison’ WHERE [Link] = [Link] AND [Link] = [Link] AND [Link] = ‘NY’
AND [Link] <> ‘NY’ AND [Link] <> ‘NY’ AND [Link] > [Link] AND [Link] > [Link] AND
[Link] < 1800 ))
10) SELECT [Link] - [Link] FROM ( SELECT AVG ([Link]) AS avg FROM Employees E WHERE
[Link] IN (SELECT DISTINCT [Link] FROM Certified C )) AS Temp1, ( SELECTAVG ([Link]) AS avg FROM
Employees E1 ) AS Temp2