Exercises
Best Airlines MECHANIC table MECHNUM MECHNAM E TELEPHON E SALARY AIRNAME SIZE YEAROPEN ED AIRPORT table AIRNAME CITY STATE SKILL table SKILLNUM SKILLNAME SKILLCAT QUALIFICATION table MECHNUM SKILLNUM YEARQUAL PRORATE 9-2 9-2
Best Airlines a. List the names and telephone numbers of all of the mechanics. Select mechname, telephone from mechanic; 9-3 9-3
9-4 9-4
Best Airlines b. List the airports in California that are at least twenty acres in size and have been open since 1935. Order the results from smallest to largest airport. Select airname from airport where size >= 20 and State = California and yearopened <= 1935 order by size asc; 9-5 9-5
9-6 9-6
9-7 9-7
Best Airlines c. List the airports in California that are at least 20 acres in size or have been open since 1935. Select airname From airport Where state = California and (size >= 20 or yearopened <= 1935); 9-8 9-8
9-9 9-9
9-10 9-10
Best Airlines d. Find the average size of the airports in California that have been open since 1935. Select avg(size) From airport Where state = California And yearopened <= 1935; 9-11 9-11
9-12 9-12
9-13 9-13
Best airlines e. How many airports have been open in California since 1935? Select count(*) From airport Where state = California and yearopened <= 1935; 9-14 9-14
9-15 9-15
9-16 9-16
Best airlines f. How many airports have been open in each state since 1935? Select state, count(*) From airport Where yearopened <= 1935 Group by state; 9-17 9-17
9-18 9-18
9-19 9-19
Best airlines g. How many airports have been open in each state since 1935? Only include in your answer those states that have at least five such airports. Select state, count(*) From airport Where yearopened <= 1935 Group by state Having count(*) >= 5; 9-20 9-20
9-21 9-21
9-22 9-22
Best airlines h. List the names of the mechanics who work in California. Select Mechname From mechanic, airport Where mechanic.airname = airport.airname and state = California ; 9-23 9-23
9-24 9-24
9-25 9-25
Best airlines i. Fan blade replacement is the name of a skill. List the names of the mechanics who have a proficiency rating of 4 in fan blade replacement. Select mechname From skill, qualification, mechanic Where skill.skillnum = qualification.skillnum and qualification.mechnum = mechanic.mechnum and skillname = Fan Blade Replacement and profrate = 4; 9-26 9-26
9-27 9-27
9-28 9-28
Best airlines j. Fan blade replacement is the name of a skill. List the names of the mechanics who work in California who have a proficiency rating of 4 in fan blade replacement. Select mechname From skill, qualification, mechanic, airport Where skill.skillnum = qualification.skillnum and qualification.mechnum = mechanic.mechnum and mechanic.airname = airport.airname and skillname = Fan Blade Replacement and state = California and profrate = 4; 9-29 9-29
9-30 9-30
9-31 9-31
Best airlines k. List the total, combined salaries of all of the mechanics who work in each city in California. Select city, sum(salary) From mechanic, airport Where mechanic.airname = airport.airname and state = California Group by city; 9-32 9-32
9-33 9-33
9-34 9-34
Best airlines l. Find the largest of all of the airports. Select airname From airport Where size= (select max(size) from airport); 9-35 9-35
9-36 9-36
9-37 9-37
Best airlines m. Find the largest airport in California. Select airname From airport Where state = California and size = (select max(size) from airport where state = California ); 9-38 9-38
9-39 9-39
9-40 9-40
Quality Appliance SUPPLIER table SUPPLIERNU M SUPPLIERNAM E CITY COUNTRY TELEPHON E COST APPLIANCE NUM BUYERNU M PRICE COUNTRY CREDITRATI NG PART table PARTNUM SUPPLIERNUM PARTTY PE APPLIANCE table APPLIANCENU M APPLIANCETYP E DATEMA NUF BUYER table BUYERNUM BUYERNAME CITY INSPECTOR table INSPECTORNU M INSPECTORNAM E SALARY DATEHIRE INSPECTION table APPLIANCENU M INSPECTORNUM DATEINSPECT ION SCORE 9-41 9-41
Quality Appliance a. List the names, in alphabetic order, of the suppliers located in London, Liverpool, or Manchester, UK Select suppliername From supplier Where city in ( London, Liverpool, Manchester ) 9-42 9-42
9-43 9-43
9-44 9-44
Quality Appliance b. List the names of the suppliers that supply motors (see PARTTYPE) costing between $50 and $100. Select suppliername From supplier, part Where supplier.suppliernum = part.suppliernum And parttype = 'Motors' And cost between 50 and 100; 9-45 9-45
9-46 9-46
9-47 9-47
Quality Appliance c. Find the average cost of the motors (see PARTTYPE) supplied by supplier number 3728. select avg(cost) from part where parttype = 'Motors' and suppliernum = 3728; 9-48 9-48
9-49 9-49
9-50 9-50
Quality Appliance d. List the names of the inspectors who were inspecting refrigerators (see appliancetype) on April 17, 2003. Select inspectorname From inspector, inspection, appliance Where inspector.inspectornum = inspection.inspectornum and inspection.appliancenum = appliance.appliancenum and appliancetype = Refrigerator and dateinspection = 9-51 9-51 #APR-17-2003#;
9-52 9-52
9-53 9-53
Quality Appliance e. What was the highest inspection score achieved by a refrigerator on November 3, 2003? Select max(score) From inspection, appliance Where inspection.appliancenum = appliance.appliancenum and appliancetype = Refrigerator and dateinspection = #NOV-03-2003#; 9-54 9-54
9-55 9-55
9-56 9-56
Quality Appliance f. Find the total amount of money spent on Quality Appliance products by each buyer from Mexico, Venezuela, and Argentina. Select buyer.buyernum, sum(price) From appliance, buyer Where appliance.buyernum = buyer.buyernum and country in ( Mexico, Venezuela, Argentina ) Group by buyer.buyernum; 9-57 9-57
9-58 9-58
9-59 9-59
Quality Appliance g. Find the total cost of the parts used in each dishwasher manufactured on February 28, 2004. Only include in the results those dishwashers that used at least $200 in parts. Select appliance.appliancenum, sum(cost) From appliance, part Where appliance.appliancenum = part.appliancenum and appliancetype = Dishwasher and datemanuf = #FEB28-2004# Group by appliance.appliancenum Having sum(cost) >= 200; 9-60 9-60
9-61 9-61
9-62 9-62
Quality Appliance h. List the highest paid inspectors. Select inspectornum From inspector Where salary = (select max(salary) from inspector); 9-63 9-63
9-64 9-64
9-65 9-65
Quality Appliance i. List the highest paid inspector who were hired in 2002. Select inspectornum From inspector Where datehire between #JAN-01-2002# and #DEC-312002# and salary = (select max(salary) from inspector Where datehire between 9-66 9-66 #JAN-01-2002# and #DEC-31-2002#);
9-67 9-67
9-68 9-68
Quality Appliance j. Among all of the inspectors, list those who earn more money than the highest paid inspector who was hired in 2002. Select inspectornum From inspector Where salary > (select max(salary) from inspector Where datehire between #JAN-01-2002# and #DEC-31-2002#); 9-69 9-69
9-70 9-70
9-71 9-71