Sei sulla pagina 1di 9

IE462 Sheet #2: SQL 2.1 Consider the tables in the given figures.

Write the SQL code for the queries that will return the following:

(a) The PO details associated with Purchase Order 2594:

(b) The list of purchase order numbers, without duplication, that have an OPEN line item:

(c) The following PO details from purchase orders placed with Vendor V250: PO_NUMBER, PO_LINE_ITEM, MATERIAL_ID, QUANTITY, UNIT_COST, TOTAL_COST (QUANTITY UNIT_COST): (d) Repeat part c, but order the result by TOTAL_COST increasing:

(e) Return the number of purchase orders whose PO_AMT is greater than 3000:

(f) Return the vendor ID, without duplication, of any vendor having an open PO line item where quantity times unit cost is more than $500:

2.2 The human resources department of an enterprise maintains a database on the companys employees in order to track their qualifications at various skill levels. The tables are as follows.

All attributes are text data types except DATE_QUALIFIED, which is a date data type. The database can be downloaded from the web site supporting this book.

(a) Identify the primary key(s) and foreign key(s) of each table. (b) Write the SQL commands to return the following data from the database: (1) The first and last names of the employees who work in Department 30: (2) The first and last names of employees with the SKILL_ID of 110 (3) The first and last names of the employees who are C Programmers (4) The number of Java Programmers in Department 30 (5) The last and first names of the Java Programmers in Department 30 listed alphabetically by last name (6) The department ID and department name, listed without repetition, of any departments that do not have Java Programmers. 2.3 The ACME Machine Shop is a small job shop that does machining of components for customers that assemble finished products. The customers give ACME engineering drawings of parts and request production of parts from ACME as needed. The manager of the machine shop has used a database to try to organize some basic information on the customers parts and their machining requirements as well as scheduling information based on orders. The tables and their design requirements are shown here. The meaning of the tables is as follows: PART The parts produced by ACME PROCESS_PLAN The operations that must be performed to manufacture the parts MACHINE The machines used to manufacture the parts SCHEDULE A set of production schedules for part manufacture

(a) Write the SQL code that will generate answers to the following questions: (1) List all the entries from the parts table. (2) List the instances of parts that use raw material RM302. (3) List the instances of all parts, alphabetically ordered by part description. (4) List the instances of all schedules with lot sizes greater than 15. (5) List the instances of all parts that require machine M1. (6) List the machines and their average, minimum, and maximum unit machining times. (7) For each schedule, list the schedule ID, part number, operation number, machine ID, setup time, total machining time, and total time (setup plus machining). Be sure that each attribute column has a title. (8) List the tooling that is used with each raw material without repetition in the tuple. (9) List the schedule release date, part number that will be machined, and machine ID that will be used by schedule release date descending. (10) List the part number and machine ID that will be used in production on schedule release date 4/1/06. (11) List just the machine ID (without duplication) that will be used by schedules released on 4/1/06.

(12) Using a query/sub-query, list all the part numbers that have operations with a setup time greater than 8 minutes. (13) List the material ID and the number of pieces of raw material that will be required for all the scheduled job releases on 4/1/06. 2.4 The ACME metalworking Machine Shop has implemented a highly automated cellular manufacturing system. In this system, machines are grouped into autonomous machining cells, each attended by a robot for material handling. Parts to be machined are moved to the cells by an automated guided vehicle (AGV). When a part is taken to a specific cell, it is completely manufactured within that cell. Some parts can be produced in either cell. ACME has implemented two cells, as shown here:

ACME has designed a database and implemented some tables that describe the relationships between cells, machines, and the parts that they produce. The Access database can be downloaded from the web site supporting this book. The tables are shown here and have the following meaning: CELL Identifies the different cells MACHINE Identifies the different machines PART Identifies the different parts manufactured in the cells PROCESS_PLAN Identifies the different possible process plans that can be used to manufacture each part (some parts can be manufactured by more than one process plan) PROCESS_PLAN_STEP Defines each operation of each process plan and the machines used in the operation.

(a) For each table identify the primary key(s) and foreign key(s). (b) Write the SQL statements for the following: (1) A list of machines by cell.

(2) The minimum, maximum, and average processing time on a machine:

(3) The total machining time by cell and by part:

Potrebbero piacerti anche