I have these three tables here
- Aircraft (aid, aname, cruisingrange)
- Employee (eid, ename, salary)
- Certified (eid, aid)
For aircraft with cruisingrange over 1000 miles, SELECT
the aircraft name and the average salary of all pilots who have flown these aircrafts.
Note that pilot and employee are the same.
I spent a lot time thinking about this problem but I couldn’t write a SQL query. Please help me
Advertisement
Answer
here is the query that shows avg salary of pilots who flown aircraft with over 1000 miles:
x
select
aname
, AVG(salary) AvgSalary
from
AirCraft
join Certified
on AirCraft.aid = Certified.aid
and Aircraft.cruisingrange > 1000
join Employee
on Employee.eid = Certified.eid
group by
aname