Sample relational algebra problems
All are based on the following airline database schema:
Flights(flno, from, to, distance, departs)
Aircraft(aid, aname, range)
Certified(eid, aid)
Employees(eid, ename, salary)
By definition, pilots are those employees who are certified on at least one aircraft. An aircraft can be used for any flight provided it
has sufficient range. Pilots can pilot any flight provided they are certified on an aircraft with sufficient range.
Problems
1. Find eid’s of pilots who are certified on some Boeing.
2. Find names of pilots who are certified on some Boeing.
3. Find aid’s of aircraft that can fly non-stop from LA to NY. Assume you don’t already know the distance.
4. Find flno of flights that can be piloted by every pilot whose salary is over $100,000.
5. Solve problem 4 without using the division operator.
6. Find names of pilots who can operate planes with a range greater than 3,000 miles, but are not certified on any Boeing.
7. Find eid of employee(s) with the highest salary.
8. Find eid of employee(s) with the second highest salary.
9. Find eid of employee(s) certified on the most aircraft.
Solutions
1. eid (aname = ‘Boeing’ (Aircraft Certified))
2. ename (aname = ‘Boeing’ (Aircraft Certified Employees))
3. aid (range distance (Aircraft x from = ‘LA’ ^ to = ‘NY’ (Flignts)))
4. flno,eid (range distance (Aircraft x Flights) Certified)
÷ eid (salary > 100000 (Employees Certified))
5. flno (Flights) - flno ( (flno (Flights) x eid (salary > 100000 (Employees Certified)))
- flno,eid (range distance (Aircraft x Flights) Certified) )
6. ename (Employees
(eid (range > 3000 (Aircraft Certified)) - eid (name = ‘Boeing’ (Aircraft Certified)))
7. eid (Employees) - e2.eid (e1.salary > e2.salary (e1 (Employees) x e2 (Employees)))
8. temp e2.eid, e2.salary (e1.salary > e2.salary (e1 (Employees) x e2 (Employees))
result eid (temp) - e2.eid (e1.salary > e2.salary (e1 (temp) x e2 (temp)))
9. There is no solution to this problem using relational algebra.