sql - How to obtain many-to-many relationship querys in Oracle? -


i beginner , trying solve these queries didn't way can 1 please me.

the following relations keep track of airline flight information :

create table flights(       flno     number(10) primary key,      ffrom    varchar2(50),      fto      varchar2(50),      distance number(10),      departs  varchar2(50),      arrivs   varchar2(50),      price    number(10,2) );  create table aircraft(     aid            number(10)  primary key,     aname          varchar2(50),     cruisingrange  number(10) );  create table employees(     eid           number(10)  primary key,     ename         varchar2(50),     salary        number(10,2) ); create table certified(     eid           number(10) references employees(eid),     aid           number(10) references aircraft(aid)  ); 
 flights  +------+-------------+----------+----------+---------+--------+-------+ | flno |    ffrom    |   fto    | distance | departs | arrivs | price | +------+-------------+----------+----------+---------+--------+-------+ | 1234 | los angeles | honolulu |     1100 | 9:15    | 21:45  | 25000 | | 1235 | los angeles | honolulu |     1100 | 11:20   | 22:15  | 15000 | | 1236 | los angeles | delhi    |     3100 | 6:45    | 23:45  | 25000 | | 1237 | london      | newyork  |     2400 | 7:25    | 21:00  | 35000 | +------+-------------+----------+----------+---------+--------+-------+  aircraft +-----+-------+---------------+ | aid | aname | cruisingrange | +-----+-------+---------------+ |   1 | bb111 |          2000 | |   2 | aa123 |          5000 | |   3 | aa555 |           900 | |   4 | bb777 |           500 | +-----+-------+---------------+  employees +-----+-------+--------+ | eid | ename | salary | +-----+-------+--------+ | 301 | aaa   |  14000 | | 302 | bbb   |  12000 | | 303 | ccc   |  25000 | | 304 | ddd   |   5000 | | 305 | eee   |  50000 | | 306 | fff   |  15000 | | 307 | ggg   |  65000 | +-----+-------+--------+  certified +-----+-----+ | eid | aid | +-----+-----+ | 301 |   1 | | 302 |   3 | | 303 |   2 | | 306 |   4 | | 307 |   1 | +-----+-----+ 

the employee relation describes pilots , other kinds of employees well; every pilot certified aircraft, , pilots certified fly.

i trying following queries

  1. find names of pilots salary less price of cheapest route los angeles honolulu.

  2. for aircraft cruising range on 1000 miles, find name of aircraft , average salary of pilots certified aircraft.

i tried query first 1

 select ename employees full natural join  certified                 salary <(select min(price) flightsz   ffrom='los angles' , fto='honolulu'); 

the second 1 this:

 select aircraft.aname,avg(employees.salary) average   aircraft inner join certified on    certified.aid =aircraft.aid  inner join employees on employees.eid = certified.eid aircraft.cruisingrange > 1000   group aname 

aplying avg function group allows average salary.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -