exercise 2 10csl57 dbms lab program 2
DESCRIPTION
DBMS LAB MANUAL 10CSL57 2ND PROGRAM WITH QUERIES AND OUTPUTTRANSCRIPT
EXERCISE 2 – AIRLINE FLIGHT INFORMATION
2 . The following relations keep track of airline flight information:
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.
Write each of the following queries in SQL.
1. Find the names of aircraft such that all pilots certified to operate them have salaries more than
Rs.80, 000.
2. For each pilot who is certified for more than three aircrafts, find the eid and the maximum
cruisingrange of the aircraft for which she or he is certified.
3. Find the names of pilots whose salary is less than the price of the cheapest route from
Bengaluru to Frankfurt.
4. For all aircraft with cruisingrange over 1000 Kms, .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.
6. Find the aids of all aircraft that can be used on routes from Bengaluru to New Delhi.
Creation of Tables:
SQL> create table flights(flno int primary key,from1 varchar2(10),to1 varchar2(10)
rts timestamp,arrives timestamp,price number(6,2));
Table created.
SQL> create table aircraft(aid int primary key,aname varchar2(10),crusingrange int
Table created.
SQL> create table employees(eid int primary key,ename varchar2(10),salary int);
Table created.
SQL> create table certified(eid references employees(eid),aid references aircraft(
Table created.
SQL> desc flights;
Name Null? Type
----------------------------------------- -------- ----------------------------
FLNO NOT NULL NUMBER(38)
FROM1 VARCHAR2(10)
TO1 VARCHAR2(10)
DISTANCE NUMBER(38)
DEPARTS TIMESTAMP(6)
ARRIVES TIMESTAMP(6)
PRICE NUMBER(6,2)
SQL> desc aircraft;
Name Null? Type
----------------------------------------- -------- ----------------------------
AID NOT NULL NUMBER(38)
ANAME VARCHAR2(10)
CRUSINGRANGE NUMBER(38)
SQL> desc employees;
Name Null? Type
----------------------------------------- -------- ----------------------------
EID NOT NULL NUMBER(38)
ENAME VARCHAR2(10)
SALARY NUMBER(38)
SQL> desc certified;
Name Null? Type
----------------------------------------- -------- ----------------------------
EID NUMBER(38)
AID NUMBER(38)
Insertion o f Values:-
insert into flights values('&flno','&from1','&to1','&distance','&departs','&arrives','&price');
insert into aircraft values('&aid','&aname','&cruisingrange');
insert into employees values('&eid','&ename','&salary');
insert into certified values('&eid','&aid')
SQL> select * from flights;
FLNO FROM1 TO1 DISTANCE
---------- ---------- ---------- ----------
DEPARTS
---------------------------------------------------------------------
ARRIVES
---------------------------------------------------------------------
PRICE
----------
1111 bang franfurt 10000
22-SEP-20 12.10.00.000000 PM
22-SEP-20 12.15.00.000000 PM
1000
FLNO FROM1 TO1 DISTANCE
---------- ---------- ---------- ----------
DEPARTS
---------------------------------------------------------------------
ARRIVES
---------------------------------------------------------------------
PRICE
----------
2222 bangalore frankfurt 10000
23-SEP-20 12.00.00.000000 PM
24-SEP-20 12.17.00.000000 PM
2000
FLNO FROM1 TO1 DISTANCE
---------- ---------- ---------- ----------
DEPARTS
---------------------------------------------------------------------
ARRIVES
---------------------------------------------------------------------
PRICE
----------
3333 bangalore newdelhi 700
25-OCT-20 12.07.00.000000 PM
25-OCT-20 12.09.00.000000 PM
200
FLNO FROM1 TO1 DISTANCE
---------- ---------- ---------- ----------
DEPARTS
---------------------------------------------------------------------
ARRIVES
---------------------------------------------------------------------
PRICE
----------
4444 los hono 1000
23-SEP-20 12.10.00.000000 PM
23-SEP-20 12.12.00.000000 PM
100
FLNO FROM1 TO1 DISTANCE
---------- ---------- ---------- ----------
DEPARTS
---------------------------------------------------------------------
ARRIVES
---------------------------------------------------------------------
PRICE
----------
5555 bang frankfurt 1000
24-SEP-20 12.10.00.000000 PM
25-SEP-20 12.12.00.000000 PM
100
SQL> select * from aircraft;
AID ANAME CRUSINGRANGE
---------- ---------- ------------
11 boeing 2000
22 boeingt 1500
33 boeing 1000
44 airindia 1200
55 airdeccan 1000
SQL> select * from employees;
EID ENAME SALARY
---------- ---------- ----------
1 niyaz 90000
2 kiran 10000
3 ranjith 10000
4 chetan 10000
5 ajay 10000
SQL> select * from certified;
EID AID
---------- ----------
1 11
2 22
2 33
2 44
2 55
3 22
4 44
1) SQL> select a.aname from aircraft a
where a.aid in(select c.aid from certified c,employees e where c.eid=e.eid and NOT EXISTS (sele
ct * from employees e1 where e1.eid=e.eid and e1.salary<80000));
ANAME
----------
boeing
2) SQL> select c.eid,max(a.crusingrange)
2 from certified c,aircraft a
3 where c.aid=a.aid
4 group by c.eid
5 having count(*)>3;
EID MAX(A.CRUSINGRANGE)
---------- -------------------
2 1500
3)
SQL> select min(f.price) from flights f where f.from1='bang' and f.to1='frankfurt';
MIN(F.PRICE)
------------
100
SQL> update employees set salary='90' where eid=2;
1 row updated.
SQL> select * from employees;
EID ENAME SALARY
---------- ---------- ----------
1 niyaz 90000
2 kiran 90
3 ranjith 10000
4 chetan 10000
5 ajay 10000
SQL> select e.ename
2 from employees e
3 where e.salary<(select min(f.price) from flights f where f.from1='bang' and f.to1='frankfurt');
ENAME
----------
kiran
4)
SQL> select aname,avg(salary)
2 from aircraft a,certified c,employees e
3 where crusingrange>1000 and c.aid=a.aid and c.eid=e.eid
4 group by aname;
ANAME AVG(SALARY)
---------- -----------
airindia 5045
boeing 90000
boeingt 5045
5)
SQL> select distinct e.ename
2 from employees e,certified c,aircraft a
3 where e.eid=c.eid and c.aid=a.aid and a.aname like '%boeing%';
ENAME
----------
kiran
niyaz
ranjith
6) SQL> select a.aid
2 from aircraft a
3 where a.crusingrange >(select distance from flights f where f.from1='bangalore' and
4 f.to1='newdelhi');
AID
----------
11
22
33
44
55
*********************************end ***************************************