Vous êtes sur la page 1sur 3

--SELECT

--SELECT
--SELECT
--SELECT

*
*
*
*

FROM
FROM
FROM
FROM

dbo.Aircraft A
dbo.Certified C
dbo.Employees E
dbo.Flights F

--SELECT * FROM dbo.Aircraft A inner join dbo.Certified C inner join


dbo.Employees E
-------------------------------------------------------------------------------------------------------------------1--Find the names of aircraft such that all pilots certified to operate them
earn more than $80,000.
--SELECT Aname FROM dbo.Aircraft A inner join dbo.Certified C inner join
dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--where E.Salary< 80000
--------------------------------------------------------------------------------------------------------------------2--For each pilot who is certified for more than three aircraft,
----find the eid and the maximum cruisingrange of the aircraft for which she or
he is certified.
--SELECT max(Crusing_range)as cruse_range FROM dbo.Aircraft A inner join
dbo.Certified C inner join dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--group by c.E_id
-having COUNT(*)>2
----------------------------------------------------------------------------------------------------------------------3--Find the names of pilots whose salary is less than the price of the
cheapest route from Los Angeles to Honolulu.
--SELECT E_name FROM dbo.Flights f inner join dbo.Certified C inner join
dbo.Employees E
--on c.E_id=E.E_id
--on f.Fl_no=c.A_id
--where e.Salary< (select Price from Flights f where(f.[From]='Los angeles' and
f.[To]='Honolulu'))
------------------------------------------------------------------------------------------------------------------------4-- For all aircraft with cruisingrange over 30000 miles,
----find the name of the aircraft and the average salary of all pilots certified
for this aircraft.
--SELECT Aname, AVG(Salary)as salary FROM dbo.Aircraft A inner join
dbo.Certified C inner join dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--where a.Crusing_range> 30000
--group by Salary , Aname
------------------------------------------------------------------------------------------------------------------------

--5-- Find the names of pilots certified for some fly aircraft.
--SELECT E_name, Aname FROM dbo.Aircraft A inner join dbo.Certified C inner join
dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--where A.Aname like '%fly%'
--------------------------------------------------------------------------------------------------------------------------6-- Find the aids of all aircraft that can be used on routes from China to
Calcutta.
--SELECT A_id FROM dbo.Flights f inner join dbo.Certified C inner join
dbo.Employees E
--on c.E_id=E.E_id
--on f.Fl_no=c.A_id
--where f.[From]='China' or f.[To]='Calcutta'
--------------------------------------------------------------------------------------------------------------------------7--Identify the routes that can be piloted by every pilot who makes more than
$100,000
--SELECT [From],[To] FROM dbo.Flights f inner join dbo.Certified C inner join
dbo.Employees E
--on c.E_id=E.E_id
--on f.Fl_no=c.A_id
--where e.Salary>100000
---------------------------------------------------------------------------------------------------------------------------8--Print the enames of pilots who can operate planes with cruisingrange
greater than 10000 miles
--but are not certified on any fly aircraft.
--SELECT E_name, Aname,Crusing_range FROM dbo.Aircraft A inner join
dbo.Certified C inner join dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--where Crusing_range>30000 and Aname not like '%fly'
-----------------------------------------------------------------------------------------------------------------------------9-- A customer wants to travel from Madison to New York with no more than two
changes of flight.
--List the choice of departure times from Madison if the customer wants to
arrive in New York by 6 p.m.
-----------------------------------------------------------------------------------------------------------------------------10--Compute the difference between the average salary of a pilot and the
average salary of all employees (including pilots).
--select f.avsalary-j.sal from (
--Select avg(salary)as avsalary from dbo.Employees E inner join dbo.Certified c

--on E.E_id=c.E_id) f
--,(
--select AVG(salary) as sal from dbo.Employees E) j
-------------------------------------------------------------------------------------------------------------------------------11--Print the name and salary of every nonpilot whose salary is more than the
average salary for pilots.
--select E_name,salary from dbo.Employees E
--where E.Salary>(select avg(salary) as piavg from dbo.Employees e inner join
dbo.Certified c
--on e.E_id=c.E_id)
--and E_id not in (select E_id from Certified)
-------------------------------------------------------------------------------------------------------------------------------12--Print the names of employees who are certified only on aircrafts with
cruising range longer than 1000 miles
--SELECT E_name, Aname,Crusing_range FROM dbo.Aircraft A inner join
dbo.Certified C inner join dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--where Crusing_range>30000
------------------------------------------------------------------------------------------------------------------------------13-- Print the names of employees who are certified
--only on aircrafts with cruising range longer than 1000 miles, but on at least
two such aircrafts.
--SELECT E_name FROM dbo.Aircraft A inner join dbo.Certified C inner join
dbo.Employees E
--on c.E_id=E.E_id
--on a.A_id=c.A_id
--group by E_name,Crusing_range
--having(Crusing_range>20000 and COUNT(*)>1)
-------------------------------------------------------------------------------------------------------------------------------

Vous aimerez peut-être aussi