SlideShare a Scribd company logo
1 of 6
Download to read offline
Database Systems
                                                               Instructors: Hao-Hua Chu
                                                                            Winston Hsu
                                                                     Fall Semester, 2007

                         Assignment 3: SQL Queries

   Questions
1. The following relations keep track of airline flight information:

           Flights(flno: integer, from: string, to: string, distance: integer, departs:
           time,
           arrives: time, price: integer)
           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
   aswell; every pilot is certified for some aircraft, and only pilots are certified to
   fly.Write each of the following queries in SQL.

   a. Find the names of aircraft such that all pilots certified to operate them earn
      more than $80,000.
   b. 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.
   c. Find the names of pilots whose salary is less than the price of the cheapest
      route from Los Angeles to Honolulu.
   d. For all aircraft with cruisingrange over 1000 miles, find the name of the
      aircraft and the average salary of all pilots certified for this aircraft.
   e. Find the names of pilots certified for some Boeing aircraft.
   f. Find the aids of all aircraft that can be used on routes from Los Angeles to
      Chicago.
   g. Identify the routes that can be piloted by every pilot who makes more than
      $100,000.
   h. Print the enames of pilots who can operate planes with cruisingrange greater
      than 3000 miles but are not certified on any Boeing aircraft.
   i. 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.
   j. Compute the difference between the average salary of a pilot and the average
      salary of all employees (including pilots).
   k. Print the name and salary of every nonpilot whose salary is more than the
      average salary for pilots.
) ’ o g a ci h C ‘ = ot. F       AND    ’ s el e g n A s o L ‘ = m orf. F     WHERE
                                                                       F st h gil F
                                                                               FROM
                                                        ) e c n at si d. F (    SELECT MIN                   ( > e g n a r g ni si u r c. A    WHERE
                                                                                                                            A tf ar cri A      FROM
                                                                                                                                   di a. A     SELECT   .f
                        ’ %gn ieo B ‘         LIKE      e m a n a. A   AND           dia.A = dia.C           AND         die.C = die.E         WHERE
                                                                               A tfarcriA ,C deifitreC ,E seeyolpmE                            FROM
                                                                                                      e m a n e. E        DISTINCT             SELECT   .e
                                                                   p me T        AS    ) emana.A ,dia.A                  GROUP BY
            0 0 0 1 > e g n ar g ni si ur c. A   AND     die.E = die.C         AND            di a. C = di a. A          WHERE
                                                    E seeyolpmE ,C deifitreC ,A tfarcriA                                 FROM
                    yr al a S g v A   AS   ) yr al a s. E(   AVG    ,e man       AS       emana.A ,dia.A                  SELECT          (    FROM
                                                                                           y r al a S g v A. p m e T , e m a n. p m e T        SELECT
                                                                      :pmeT noitaler etaidemretni na gnisu yb noitacilpmoc
    siht htiw laed ew ;seman tfarcria rof sksa noitseuq eht tub ,tfarcriA rof yek eht si dia taht evresbO                                               .d
        ) ’ ul ul o n o H ‘ = ot. F     AND        ’ s el e g n A s o L ‘ = m orf. F   WHERE
                                                                                       F st h gil F
                                                                                       FROM
                                                                    ) e cir p. F (      SELECT MIN                   (       < y r al a s. E   WHERE
                                                                                                                         E s e e y ol p m E    FROM
                                                                                                      e m a n e. E        DISTINCT             SELECT   .c
                                                                                                           3 > ) *(      COUNT            HAVING
                                                                                                                              di e. C     GROUP BY
                                                                                                                 di a. A = di a. C        WHERE
                                                                                                 A tfarcriA ,C deifitreC                  FROM
                                                                                    ) e g n a r g ni si u r c. A (   MAX     , di e. C    SELECT        .b
  )) 0 0 0 0 8 < yr al a s. 1 E   AND   die.E = die.1E           WHERE
                                            1 E s e e y ol p m E FROM
                                                             *    SELECT        (         NOT EXISTS
                                                                    AND  die.E = die.C    WHERE
                                                        E seeyolpmE ,C deifitreC          FROM
                                                                                       di a. C
                                                                                           SELECT                    (        IN   di A. A     WHERE
                                                                                                                            A tf ar cri A      FROM
                                                                                                     e m a n a. A         DISTINCT             SELECT   .a
                                                                                                                                                        Ans:
   range longer than 1000 miles and who are certified on some Boeing aircraft.
n. 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.
m. Print the names of employees who are certified only on aircrafts with cruising
   range longer than 1000 miles.
l. Print the names of employees who are certified only on aircrafts with cruising
)) ’ 0 0: 8 1 ‘ < s e virr a. 2 F          AND
                                                    s e virr a. 1 F > str a p e d. 2 F     AND
                                                    s e virr a. 0 F > str a p e d. 1 F     AND
                                                 ’ k r o Y w e N ‘ > < ot. 1 F             AND
                                                 ’ k r o Y w e N ‘ > < ot. 0 F             AND
                                                   ’ kr o Y w e N ‘ = ot. 2 F              AND
                                                               m orf. 2 F = ot. 1 F        AND
                                                               m orf. 1 F = ot. 0 F        AND
                                                           ’ n o si d a M ‘ = m orf. 0 F             WHERE
                                               2 F st h gil F , 1 F st h gil F , 0 F st h gil F      FROM
                                                                                        o nlf. 0 F    SELECT           (
                                                                                                     UNION
                                                 ) ’ 0 0: 8 1 ‘ < s e virr a. 1 F          AND
                                                    s e virr a. 0 F > str a p e d. 1 F     AND
                 ’ kr o Y w e N ‘ = ot. 1 F       AND          m orf. 1 F = ot. 0 F        AND
             ’ kr o Y w e N ‘ > < ot. 0 F          AND     ’ n o si d a M ‘ = m orf. 0 F             WHERE
                                                                1 F st h gil F , 0 F st h gil F      FROM
                                                                                        o nlf. 0 F    SELECT           (
                                                                                                     UNION
                                                 ) ’ 0 0: 8 1 ‘ < s e virr a. 0 F          AND
              ’ kr o Y w e N ‘ = ot. 0 F          AND      ’ n o si d a M ‘ = m orf. 0 F               WHERE
                                                                                    0 F st h gil F     FROM
                                                                                        o nlf. 0 F     SELECT              ((   IN   o nl f. F    WHERE
                                                                                                                                F st h gil F      FROM
                                                                                                                                st r a p e d. F   SELECT   .i
)) ’ % g ni e o B ‘   LIKE    e m a n a. 1 A     AND
                 di a. C = di a. 1 A             WHERE
                        1 A tf ar cri A          FROM
                          di a. 1 A                   (
                                      NOT EXISTS SELECT
                                      AND
                                 ) 0 0 0 3 > e g n ar g ni si ur c. A
                                      AND
                                      WHEREdi a. C = di a. A
                                      FROM         A tf ar cri A
                                       SELECT        di a. A                    (     WHERE EXISTS
                                                                                      C d eifitr e C
                                                                                      FROM
                                                                                      di e. C
                                                                                        SELECT                  ((               IN   di e. E     WHERE
                                                                                                                       E s e e y ol p m E         FROM
                                                                                                       e m a n e. E        DISTINCT               SELECT   .h
             ) )dia.C = dia.A         AND      die.C = die.E
              AND      e c n at si d. F > e g n ar g ni si ur c. A      WHERE
                               C deifitreC ,A tfarcriA                  FROM
                                                                *        SELECT        (   NOT EXISTS
                                                                                           AND
                                                                     0 0 0 0 0 1 > yr al a s. E
                                                                                           WHERE
                                                                            E s e e y ol p m E
                                                                                           FROM
                                                                                             *
                                                                                            SELECT                (    WHERE NOT EXISTS
                                                                                                                       FROM     F st h gil F
                                                                                                  ot. F , m o r f. F   SELECT DISTINCT                     .g
) ’ g ni e o B ’ = e m a n a. A(   AND ANY           ) 0 0 0 1 > e g n a r g ni si u r c. A (   EVERY           HAVING
                                                                                    emane.E ,die.E              GROUP BY
                                                       die.C = die.E          AND     di a. A = di a. C         WHERE
                                                  A tfarcriA ,C deifitreC ,E seeyolpmE                          FROM
                                                                                                 e m a n e. E   SELECT               .n
                  1 > ) *(   AND COUNT               ) 0 0 0 1 > e g n a r g ni si u r c. A (   EVERY           HAVING
                                                                                    emane.E ,die.E              GROUP BY
                                                       die.C = die.E          AND     di a. A = di a. C         WHERE
                                                  A tfarcriA ,C deifitreC ,E seeyolpmE                          FROM
                                                                                                 e m a n e. E   SELECT               .m
                                                     ) 0 0 0 1 > e g n a r g ni si u r c. A (   EVERY           HAVING
                                                                                    emane.E ,die.E              GROUP BY
                                                       die.C = die.E          AND     di a. A = di a. C         WHERE
                                                  A tfarcriA ,C deifitreC ,E seeyolpmE                          FROM
                                                                                                 e m a n e. E   SELECT               l.
                                            ) ) 1 C d eifitr e C
                                                         FROM
                                   di e. 1 C              SELECT DISTINCT             (
                                                 WHERE       IN               di e. 1 E
                                                 FROM           1 E s e e y ol p m E
                                                  SELECT AVG) yr al a s. 1 E(                              ( > y r al a s. E   AND
                                                 ) C d eifitr e C
                                                         FROM
                                       di e. C    NOT IN SELECT DISTINCT                  (               di e. E     WHERE
                                                                                                E s e e y ol p m E    FROM
                                                                                     yralas.E ,emane.E                SELECT         .k
                                        AS       2p me T         ) 1 E s e e y ol p m E           FROM
                             AVG         AS        gva         ) yr al a s. 1 E(                   SELECT        (
                 ,1p me T          )) C d eifitr e C
                                    FROM            AS
                             di e. C
                                 IN SELECT DISTINCT                       (        di e. E        WHERE
                                                                     E s e e y ol p m E           FROM
                                                    gva    AS    ) yr al a s. E(   AVG             SELECT        (    FROM
                                                                           gva.2pmeT - gva.1pmeT                      SELECT         .j
2. Consider the following relational schema. An employee can work in more than
      one department; the pct_time filed of the Works relation shows the percentage of
      time that a given employee works in a given department.

               Emp(eid: integer, ename: string, age: integer, salary: real)
               Works(eid: integer, did: integer, pct_time: integer)
               Dept(did: integer, dname: string, budget: real, managerid: integer)

        Write the following queries in SQL:

        a. Print the names and ages of each employee who works in both the Hardware
           department and the Software department.
        b. For each department with more than 20 full-time-equivalent employees (i.e.,
           where the part-time and full-time employees add up to at least that many full-
           time employees), print the did together with the number of employees that
           work in that department.
        c. Print the name of each employee whose salary exceeds the budget of all of the
           departments that he or she works in.
        d. Find the managerids of managers who manage only departments with budgets
           greater than $1 million.
        e. Find the enames of managers who manage the departments with the largest
           budgets.
        f. If a manager manages more than one department, he or she controls the sum
           of all the budgets for those departments. Find the managerids of managers
           who control more than $5 million.
        g. Find the managerids of managers who control the largest amounts.
        h. Find the enames of managers who manage only departments with budgets
           larger than $1 million, but at least one department with budget less than $5
           million.

Ans:
   .a   SELECT     ega.E ,emane.E
        FROM       2 D t p e D , 1 D t p e D , 2 W s kr o W , 1 W s kr o W , E p m E
        WHERE      di e. 1 W = di e. E   AND   di d. 1 D = di d. 1 W   AND    ’ er a w dr a H ‘ = e m a n d. 1 D   AND
                   di e. 2 W = di e. E   AND   di d. 2 D = di d. 2 W   AND    ’ er a wtf o S ‘ = e m a n d. 2 D

   .b   SELECT     , di d. W   COUNT     )die.W(
        FROM       W s kr o W
        GROUP BY   di d. W
        HAVING     ( < 0002    SELECT           SUM     ) e mit t c p. 1 W(
                               FROM             1 W s kr o W
                               WHERE            ) di d. W = di d. 1 W
) 0 0 0 0 0 0 5 < t e g d u b. D (         AND ANY      ) 0 0 0 0 0 0 1 > t e g d u b. D (      EVERY          HAVING
                                          e m a n e. E , di E. E
                                                     GROUP BY                            direganam.D = die.E                   WHERE
                                                                                                  D tpe D , E p m E            FROM
                                                                                                                e m a n e. E   SELECT   .h
                                 ) D p m et
                                    FROM
  )t e g d u B p m et. D p m et(    SELECT MAX               ( = t e g d u B p m et. D p m et
                                                                               WHERE
                                                         D p m et    AS     ) di r e g a n a m. D
                                                                               GROUP BY
                                                                               FROM     D tpe D
t e g d u B p m et   AS   )t e g d u b. D(   SUM     , dir e g a n a m. D       SELECT DISTINCT                           (    FROM
                                                                      dir e g a n a m. D p m et
                                                                               DISTINCT                                        SELECT   .g
                                    ) dir e g a n a m. D = dir e g a n a m. 2 D
                                                                          WHERE
                                                                          2 D tpe D
                                                                          FROM
                                                     )t e g d u b. 2 D(    SELECT SUM               (      < 0000005           WHERE
                                                                                                                 D tpe D       FROM
                                                                                                        di r e g a n a m. D    SELECT   .f
                                 )) 2 D t p e D
                                          FROM
                     )t e g d u b. 2 D(   SELECT MAX               ( = t e g d u b. D       WHERE
                                                                            D tpe D         FROM
                                                                   dir e g a n a m. D    IN SELECT          (       di e. E    WHERE
                                                                                                                 E pmE         FROM
                                                                                                                e m a n e. E   SELECT   .e
                             ) dir e g a n a m. D = dir e g a n a m. 2 D          WHERE
                                                                    2 D tpe D     FROM
                                                           tegdub .2 D        ALL SELECT     (             < 0000001           WHERE
                                                                                                                 D tpe D       FROM
                                                                                di r e g a n a m. D      DISTINCT              SELECT   .d
              ) di d. W = di d. D         AND     di e. W = di e. E                WHERE
                                           W s kr o W , D t p e D                  FROM
                                                       t e g d u b. D          ALL SELECT     (             > y r al a s. E    WHERE
                                                                                                                  E pmE        FROM
                                                                                                                e m a n e. E   SELECT   .c

More Related Content

What's hot

Analyse numérique interpolation
Analyse numérique interpolationAnalyse numérique interpolation
Analyse numérique interpolationJaouad Dabounou
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
ทฤษฎีเศษเหลือ
ทฤษฎีเศษเหลือทฤษฎีเศษเหลือ
ทฤษฎีเศษเหลือTeraporn Thongsiri
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata TheorySaifur Rahman
 
ประวัตินักคณิตศาสตร์โลก
ประวัตินักคณิตศาสตร์โลกประวัตินักคณิตศาสตร์โลก
ประวัตินักคณิตศาสตร์โลกguest694cc9f
 
Chap4 Récursivité en python
Chap4 Récursivité en pythonChap4 Récursivité en python
Chap4 Récursivité en pythonMariem ZAOUALI
 
Architecture des ordinateurs Elaboré par- ABIDA Mounir.ppt
Architecture des ordinateurs Elaboré par- ABIDA Mounir.pptArchitecture des ordinateurs Elaboré par- ABIDA Mounir.ppt
Architecture des ordinateurs Elaboré par- ABIDA Mounir.pptwafawafa52
 
Operand and Opcode | Computer Science
Operand and Opcode | Computer ScienceOperand and Opcode | Computer Science
Operand and Opcode | Computer ScienceTransweb Global Inc
 
Algorithme & structures de données Chap II
Algorithme & structures de données Chap IIAlgorithme & structures de données Chap II
Algorithme & structures de données Chap IIInes Ouaz
 
บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)
บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)
บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)sawed kodnara
 
Number Systems
Number SystemsNumber Systems
Number SystemsGaditek
 
Toc 1 | gate | Theory of computation
Toc 1 | gate | Theory of computationToc 1 | gate | Theory of computation
Toc 1 | gate | Theory of computationnarayan dudhe
 

What's hot (20)

Analyse numérique interpolation
Analyse numérique interpolationAnalyse numérique interpolation
Analyse numérique interpolation
 
15จำนวนสมาชิกเซต
15จำนวนสมาชิกเซต15จำนวนสมาชิกเซต
15จำนวนสมาชิกเซต
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
ทฤษฎีเศษเหลือ
ทฤษฎีเศษเหลือทฤษฎีเศษเหลือ
ทฤษฎีเศษเหลือ
 
POP-7 Robot with RQ-7 Platform (PDF)
POP-7 Robot with RQ-7 Platform  (PDF)POP-7 Robot with RQ-7 Platform  (PDF)
POP-7 Robot with RQ-7 Platform (PDF)
 
Pushdown Automata Theory
Pushdown Automata TheoryPushdown Automata Theory
Pushdown Automata Theory
 
ประวัตินักคณิตศาสตร์โลก
ประวัตินักคณิตศาสตร์โลกประวัตินักคณิตศาสตร์โลก
ประวัตินักคณิตศาสตร์โลก
 
Chap4 Récursivité en python
Chap4 Récursivité en pythonChap4 Récursivité en python
Chap4 Récursivité en python
 
O-NET ม.6-ลำดับและอนุกรม
O-NET ม.6-ลำดับและอนุกรมO-NET ม.6-ลำดับและอนุกรม
O-NET ม.6-ลำดับและอนุกรม
 
ลำดับเลขคณิต
ลำดับเลขคณิตลำดับเลขคณิต
ลำดับเลขคณิต
 
Architecture des ordinateurs Elaboré par- ABIDA Mounir.ppt
Architecture des ordinateurs Elaboré par- ABIDA Mounir.pptArchitecture des ordinateurs Elaboré par- ABIDA Mounir.ppt
Architecture des ordinateurs Elaboré par- ABIDA Mounir.ppt
 
pointers
pointerspointers
pointers
 
Operand and Opcode | Computer Science
Operand and Opcode | Computer ScienceOperand and Opcode | Computer Science
Operand and Opcode | Computer Science
 
arrays in c
arrays in carrays in c
arrays in c
 
Set
SetSet
Set
 
Algorithme & structures de données Chap II
Algorithme & structures de données Chap IIAlgorithme & structures de données Chap II
Algorithme & structures de données Chap II
 
บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)
บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)
บทที่ 1 อัตราส่วนตรีโกณมิติ(ม.5 พื้นฐาน)
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
Memory Reference instruction
Memory Reference instructionMemory Reference instruction
Memory Reference instruction
 
Toc 1 | gate | Theory of computation
Toc 1 | gate | Theory of computationToc 1 | gate | Theory of computation
Toc 1 | gate | Theory of computation
 

Viewers also liked

tabla de Integridar Sql Repaso examen
tabla de Integridar Sql  Repaso examentabla de Integridar Sql  Repaso examen
tabla de Integridar Sql Repaso examenAlex Yungan
 
test inteligancia
test inteliganciatest inteligancia
test inteliganciafalcoless
 
java assignment help and Help in java programming by http://www.assignmenthe...
java assignment help and Help in java programming by  http://www.assignmenthe...java assignment help and Help in java programming by  http://www.assignmenthe...
java assignment help and Help in java programming by http://www.assignmenthe...AssignmentHelpNet
 
Bus 120 course assignments wild 3 e
Bus 120 course assignments wild 3 eBus 120 course assignments wild 3 e
Bus 120 course assignments wild 3 ejudithzander
 
Dbms ii pr asg 31 1-2015
Dbms  ii pr asg 31 1-2015Dbms  ii pr asg 31 1-2015
Dbms ii pr asg 31 1-2015ankitadarji
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manualmaha tce
 
Online Hotel Room Booking System
Online Hotel Room Booking SystemOnline Hotel Room Booking System
Online Hotel Room Booking SystemAbhishek Kumar
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginnersRam Sagar Mourya
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answersvijaybusu
 

Viewers also liked (18)

tabla de Integridar Sql Repaso examen
tabla de Integridar Sql  Repaso examentabla de Integridar Sql  Repaso examen
tabla de Integridar Sql Repaso examen
 
Sql test paper
Sql test paperSql test paper
Sql test paper
 
test inteligancia
test inteliganciatest inteligancia
test inteligancia
 
java assignment help and Help in java programming by http://www.assignmenthe...
java assignment help and Help in java programming by  http://www.assignmenthe...java assignment help and Help in java programming by  http://www.assignmenthe...
java assignment help and Help in java programming by http://www.assignmenthe...
 
Bus 120 course assignments wild 3 e
Bus 120 course assignments wild 3 eBus 120 course assignments wild 3 e
Bus 120 course assignments wild 3 e
 
Dbms ii pr asg 31 1-2015
Dbms  ii pr asg 31 1-2015Dbms  ii pr asg 31 1-2015
Dbms ii pr asg 31 1-2015
 
SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
Sql queries
Sql queriesSql queries
Sql queries
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
Sql queires
Sql queiresSql queires
Sql queires
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Online Hotel Room Booking System
Online Hotel Room Booking SystemOnline Hotel Room Booking System
Online Hotel Room Booking System
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 
Hospital management system
Hospital management systemHospital management system
Hospital management system
 

Recently uploaded

Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Best Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaBest Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaShree Krishna Exports
 
Unlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfUnlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfOnline Income Engine
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxpriyanshujha201
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Roland Driesen
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876dlhescort
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Centuryrwgiffor
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 

Recently uploaded (20)

Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Best Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in IndiaBest Basmati Rice Manufacturers in India
Best Basmati Rice Manufacturers in India
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Unlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdfUnlocking the Secrets of Affiliate Marketing.pdf
Unlocking the Secrets of Affiliate Marketing.pdf
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...Boost the utilization of your HCL environment by reevaluating use cases and f...
Boost the utilization of your HCL environment by reevaluating use cases and f...
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 

Sql queries

  • 1. Database Systems Instructors: Hao-Hua Chu Winston Hsu Fall Semester, 2007 Assignment 3: SQL Queries Questions 1. The following relations keep track of airline flight information: Flights(flno: integer, from: string, to: string, distance: integer, departs: time, arrives: time, price: integer) 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 aswell; every pilot is certified for some aircraft, and only pilots are certified to fly.Write each of the following queries in SQL. a. Find the names of aircraft such that all pilots certified to operate them earn more than $80,000. b. 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. c. Find the names of pilots whose salary is less than the price of the cheapest route from Los Angeles to Honolulu. d. For all aircraft with cruisingrange over 1000 miles, find the name of the aircraft and the average salary of all pilots certified for this aircraft. e. Find the names of pilots certified for some Boeing aircraft. f. Find the aids of all aircraft that can be used on routes from Los Angeles to Chicago. g. Identify the routes that can be piloted by every pilot who makes more than $100,000. h. Print the enames of pilots who can operate planes with cruisingrange greater than 3000 miles but are not certified on any Boeing aircraft. i. 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. j. Compute the difference between the average salary of a pilot and the average salary of all employees (including pilots). k. Print the name and salary of every nonpilot whose salary is more than the average salary for pilots.
  • 2. ) ’ o g a ci h C ‘ = ot. F AND ’ s el e g n A s o L ‘ = m orf. F WHERE F st h gil F FROM ) e c n at si d. F ( SELECT MIN ( > e g n a r g ni si u r c. A WHERE A tf ar cri A FROM di a. A SELECT .f ’ %gn ieo B ‘ LIKE e m a n a. A AND dia.A = dia.C AND die.C = die.E WHERE A tfarcriA ,C deifitreC ,E seeyolpmE FROM e m a n e. E DISTINCT SELECT .e p me T AS ) emana.A ,dia.A GROUP BY 0 0 0 1 > e g n ar g ni si ur c. A AND die.E = die.C AND di a. C = di a. A WHERE E seeyolpmE ,C deifitreC ,A tfarcriA FROM yr al a S g v A AS ) yr al a s. E( AVG ,e man AS emana.A ,dia.A SELECT ( FROM y r al a S g v A. p m e T , e m a n. p m e T SELECT :pmeT noitaler etaidemretni na gnisu yb noitacilpmoc siht htiw laed ew ;seman tfarcria rof sksa noitseuq eht tub ,tfarcriA rof yek eht si dia taht evresbO .d ) ’ ul ul o n o H ‘ = ot. F AND ’ s el e g n A s o L ‘ = m orf. F WHERE F st h gil F FROM ) e cir p. F ( SELECT MIN ( < y r al a s. E WHERE E s e e y ol p m E FROM e m a n e. E DISTINCT SELECT .c 3 > ) *( COUNT HAVING di e. C GROUP BY di a. A = di a. C WHERE A tfarcriA ,C deifitreC FROM ) e g n a r g ni si u r c. A ( MAX , di e. C SELECT .b )) 0 0 0 0 8 < yr al a s. 1 E AND die.E = die.1E WHERE 1 E s e e y ol p m E FROM * SELECT ( NOT EXISTS AND die.E = die.C WHERE E seeyolpmE ,C deifitreC FROM di a. C SELECT ( IN di A. A WHERE A tf ar cri A FROM e m a n a. A DISTINCT SELECT .a Ans: range longer than 1000 miles and who are certified on some Boeing aircraft. n. 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. m. Print the names of employees who are certified only on aircrafts with cruising range longer than 1000 miles. l. Print the names of employees who are certified only on aircrafts with cruising
  • 3. )) ’ 0 0: 8 1 ‘ < s e virr a. 2 F AND s e virr a. 1 F > str a p e d. 2 F AND s e virr a. 0 F > str a p e d. 1 F AND ’ k r o Y w e N ‘ > < ot. 1 F AND ’ k r o Y w e N ‘ > < ot. 0 F AND ’ kr o Y w e N ‘ = ot. 2 F AND m orf. 2 F = ot. 1 F AND m orf. 1 F = ot. 0 F AND ’ n o si d a M ‘ = m orf. 0 F WHERE 2 F st h gil F , 1 F st h gil F , 0 F st h gil F FROM o nlf. 0 F SELECT ( UNION ) ’ 0 0: 8 1 ‘ < s e virr a. 1 F AND s e virr a. 0 F > str a p e d. 1 F AND ’ kr o Y w e N ‘ = ot. 1 F AND m orf. 1 F = ot. 0 F AND ’ kr o Y w e N ‘ > < ot. 0 F AND ’ n o si d a M ‘ = m orf. 0 F WHERE 1 F st h gil F , 0 F st h gil F FROM o nlf. 0 F SELECT ( UNION ) ’ 0 0: 8 1 ‘ < s e virr a. 0 F AND ’ kr o Y w e N ‘ = ot. 0 F AND ’ n o si d a M ‘ = m orf. 0 F WHERE 0 F st h gil F FROM o nlf. 0 F SELECT (( IN o nl f. F WHERE F st h gil F FROM st r a p e d. F SELECT .i )) ’ % g ni e o B ‘ LIKE e m a n a. 1 A AND di a. C = di a. 1 A WHERE 1 A tf ar cri A FROM di a. 1 A ( NOT EXISTS SELECT AND ) 0 0 0 3 > e g n ar g ni si ur c. A AND WHEREdi a. C = di a. A FROM A tf ar cri A SELECT di a. A ( WHERE EXISTS C d eifitr e C FROM di e. C SELECT (( IN di e. E WHERE E s e e y ol p m E FROM e m a n e. E DISTINCT SELECT .h ) )dia.C = dia.A AND die.C = die.E AND e c n at si d. F > e g n ar g ni si ur c. A WHERE C deifitreC ,A tfarcriA FROM * SELECT ( NOT EXISTS AND 0 0 0 0 0 1 > yr al a s. E WHERE E s e e y ol p m E FROM * SELECT ( WHERE NOT EXISTS FROM F st h gil F ot. F , m o r f. F SELECT DISTINCT .g
  • 4. ) ’ g ni e o B ’ = e m a n a. A( AND ANY ) 0 0 0 1 > e g n a r g ni si u r c. A ( EVERY HAVING emane.E ,die.E GROUP BY die.C = die.E AND di a. A = di a. C WHERE A tfarcriA ,C deifitreC ,E seeyolpmE FROM e m a n e. E SELECT .n 1 > ) *( AND COUNT ) 0 0 0 1 > e g n a r g ni si u r c. A ( EVERY HAVING emane.E ,die.E GROUP BY die.C = die.E AND di a. A = di a. C WHERE A tfarcriA ,C deifitreC ,E seeyolpmE FROM e m a n e. E SELECT .m ) 0 0 0 1 > e g n a r g ni si u r c. A ( EVERY HAVING emane.E ,die.E GROUP BY die.C = die.E AND di a. A = di a. C WHERE A tfarcriA ,C deifitreC ,E seeyolpmE FROM e m a n e. E SELECT l. ) ) 1 C d eifitr e C FROM di e. 1 C SELECT DISTINCT ( WHERE IN di e. 1 E FROM 1 E s e e y ol p m E SELECT AVG) yr al a s. 1 E( ( > y r al a s. E AND ) C d eifitr e C FROM di e. C NOT IN SELECT DISTINCT ( di e. E WHERE E s e e y ol p m E FROM yralas.E ,emane.E SELECT .k AS 2p me T ) 1 E s e e y ol p m E FROM AVG AS gva ) yr al a s. 1 E( SELECT ( ,1p me T )) C d eifitr e C FROM AS di e. C IN SELECT DISTINCT ( di e. E WHERE E s e e y ol p m E FROM gva AS ) yr al a s. E( AVG SELECT ( FROM gva.2pmeT - gva.1pmeT SELECT .j
  • 5. 2. Consider the following relational schema. An employee can work in more than one department; the pct_time filed of the Works relation shows the percentage of time that a given employee works in a given department. Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pct_time: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) Write the following queries in SQL: a. Print the names and ages of each employee who works in both the Hardware department and the Software department. b. For each department with more than 20 full-time-equivalent employees (i.e., where the part-time and full-time employees add up to at least that many full- time employees), print the did together with the number of employees that work in that department. c. Print the name of each employee whose salary exceeds the budget of all of the departments that he or she works in. d. Find the managerids of managers who manage only departments with budgets greater than $1 million. e. Find the enames of managers who manage the departments with the largest budgets. f. If a manager manages more than one department, he or she controls the sum of all the budgets for those departments. Find the managerids of managers who control more than $5 million. g. Find the managerids of managers who control the largest amounts. h. Find the enames of managers who manage only departments with budgets larger than $1 million, but at least one department with budget less than $5 million. Ans: .a SELECT ega.E ,emane.E FROM 2 D t p e D , 1 D t p e D , 2 W s kr o W , 1 W s kr o W , E p m E WHERE di e. 1 W = di e. E AND di d. 1 D = di d. 1 W AND ’ er a w dr a H ‘ = e m a n d. 1 D AND di e. 2 W = di e. E AND di d. 2 D = di d. 2 W AND ’ er a wtf o S ‘ = e m a n d. 2 D .b SELECT , di d. W COUNT )die.W( FROM W s kr o W GROUP BY di d. W HAVING ( < 0002 SELECT SUM ) e mit t c p. 1 W( FROM 1 W s kr o W WHERE ) di d. W = di d. 1 W
  • 6. ) 0 0 0 0 0 0 5 < t e g d u b. D ( AND ANY ) 0 0 0 0 0 0 1 > t e g d u b. D ( EVERY HAVING e m a n e. E , di E. E GROUP BY direganam.D = die.E WHERE D tpe D , E p m E FROM e m a n e. E SELECT .h ) D p m et FROM )t e g d u B p m et. D p m et( SELECT MAX ( = t e g d u B p m et. D p m et WHERE D p m et AS ) di r e g a n a m. D GROUP BY FROM D tpe D t e g d u B p m et AS )t e g d u b. D( SUM , dir e g a n a m. D SELECT DISTINCT ( FROM dir e g a n a m. D p m et DISTINCT SELECT .g ) dir e g a n a m. D = dir e g a n a m. 2 D WHERE 2 D tpe D FROM )t e g d u b. 2 D( SELECT SUM ( < 0000005 WHERE D tpe D FROM di r e g a n a m. D SELECT .f )) 2 D t p e D FROM )t e g d u b. 2 D( SELECT MAX ( = t e g d u b. D WHERE D tpe D FROM dir e g a n a m. D IN SELECT ( di e. E WHERE E pmE FROM e m a n e. E SELECT .e ) dir e g a n a m. D = dir e g a n a m. 2 D WHERE 2 D tpe D FROM tegdub .2 D ALL SELECT ( < 0000001 WHERE D tpe D FROM di r e g a n a m. D DISTINCT SELECT .d ) di d. W = di d. D AND di e. W = di e. E WHERE W s kr o W , D t p e D FROM t e g d u b. D ALL SELECT ( > y r al a s. E WHERE E pmE FROM e m a n e. E SELECT .c