Ex - No. 3 Aircraft Database
Ex - No. 3 Aircraft Database
Ex - No. 3 Aircraft Database
DESCRIPTION:
FLIGHTS
(no:integer,from:string,to:string,distance:integer,departs:time,arrives:time,price:real)
AIRCRAFT (aid:integer,aname:string,cruisingrange:integer)
CERTIFIED (eid:integer,aid:integer)
EMPLOYEES (eid:integer,ename:string,salary:integer)
NOTE that the EMPLOYEES relation describes pilots and other kinds of employees
as well;Every pilot is certified for some aircraft,and only pilots are certified to fly.
Queries:
Write each of the following queries in SQL.
(1,'Bangalore','Mangalore',360,'10:45:00','12:00:00',10000),
(2,'Bangalore','Delhi',5000,'12:15:00','04:30:00',25000),
(3,'Bangalore','Mumbai',3500,'02:15:00','05:25:00',30000),
(4,'Delhi','Mumbai',4500,'10:15:00','12:05:00',35000),
(5,'Delhi','Frankfurt',18000,'07:15:00','05:30:00',90000),
(6,'Bangalore','Frankfurt',19500,'10:00:00','07:45:00',95000),
(7,'Bangalore','Frankfurt',17000,'12:00:00','06:30:00',99000);
+-----+------------+---------------+
+-----+------------+---------------+
+-----+------------+---------------+
1.Find the names of aircraft such that all pilots certified to operate them
have salaries more than Rs 80,000.
mysql> SELECT DISTINCT a.aname
FROM aircraft a,certified c,employees e
WHERE a.aid=c.aid
AND c.eid=e.eid
AND NOT EXISTS
(SELECT *
FROM employees e1
WHERE e1.eid=e.eid
AND e1.salary<80000);
+------------+
| aname |
+------------+
| Airbus |
| Boeing |
| Jet01 |
| Airbus380 |
| Aircraft02 |
+------------+
5 rows in set (0.00 sec)
2.For each pilot who is certified for more than three aircrafts,find the eid
and the maximum cruisingrange of the aircraft for which he/she is
certified.
mysql> SELECT c.eid,MAX(cruisingrange)
FROM certified c,aircraft a
WHERE c.aid=a.aid
GROUP BY c.eid
HAVING COUNT(*)>3;
+-----+--------------------+
| eid | max(cruisingrange) |
+-----+--------------------+
| 1 | 8000 |
+-----+--------------------+
1 row in set (0.00 sec)
3.Find the names of all pilots whose salary is less than the price of the
cheapest route from Bangalore to Frankfurt.
mysql> SELECT DISTINCT e.ename
FROM employees e
WHERE e.salary<
(SELECT MIN(f.price)
FROM flight f
WHERE f.frm='Bangalore'
AND f.too='Frankfurt');
+-------+
| ename |
+-------+
| Ajay |
| Ajith |
| Arnab |
| Harry |
| Ron |
| Josh |
+-------+
6 rows in set (0.00 sec)
4.For all aircrafts with cruisingrange over 1000 kms,find the name of the
aircraft and the average salary of all pilots certified for this aircraft.
mysql> SELECT a.aid,a.aname,AVG(e.salary)
FROM aircraft a,certified c,employees e
WHERE a.aid=c.aid
AND c.eid=e.eid
AND a.cruisingrange>1000
GROUP BY a.aid,a.aname;
+-----+-----------+---------------+
| aid | aname | avg(e.salary) |
+-----+-----------+---------------+
| 302 | Boeing | 73333.3333 |
| 306 | Jet01 | 57500.0000 |
| 378 | Airbus380 | 53333.3333 |
+-----+-----------+---------------+
3 rows in set (0.01 sec)
5.Find the names of pilots certified for some Boeing aircraft.
mysql> SELECT distinct e.ename
FROM employees e,aircraft a,certified c
WHERE e.eid=c.eid
AND c.aid=a.aid
AND a.aname='Boeing';
+-------+
| ename |
+-------+
| Ajay |
| Ron |
| Ram |
+-------+
3 rows in set (0.00 sec)
6.Find the aid's of all aircraft that can be used on routes from Bangalore to
Delhi.
mysql> SELECT a.aid
FROM aircraft a
WHERE a.cruisingrange>
(SELECT MIN(f.distance)
FROM flight f
WHERE f.frm='Bangalore'
AND f.too='Delhi');
+-----+
| aid |
+-----+
| 378 |
+-----+
1 row in set (0.00 sec)