Case Study 3
Instructions
- Answer Exercises 2.40 through 2.60 found at the end of Chapter 2, as well as the additional "2.61" question given.
- Use both the INVENTORY and WAREHOUSE tables to answer Questions 2.40 through 2.55.
- Use both the CATALOG_SKU_2016 and CATALOG_SKU_2017 tables to answer Questions 2.56 through 2.60.
- Deliver a single sql file, along with a document that contains all the content from the sql file.
- Each query should start with a comment line that looks like:
/* *** CS3-<CH.Q> *** */
Example for Question 2.40:
/* *** CS3-2.40*** */ - Do not include the result table unless specifically directed to.
- Include at least one line of white space between answers.
Questions 2.40 - 2.61
2.40) Write a SQL statement to display the SKU, SKU_Description, WarehouseID, WarehouseCity, and WarehouseState for all items stored in the Atlanta, Bangor, or Chicago warehouse. Do not use the IN keyword.
2.41) Write a SQL statement to display the SKU, SKU_Description, WarehouseID, WarehouseCity, and WarehouseState for all items stored in the Atlanta, Bangor, or Chicago warehouse. Use the IN keyword.
2.42) Write a SQL statement to display the SKU, SKU_Description, WarehouseID, WarehouseCity, and WarehouseState of all items not stored in the Atlanta, Bangor, or Chicago warehouse. Do not use the NOT IN keyword.
2.43) Write a SQL statement to display the SKU, SKU_Description, WarehouseID, WarehouseCity, and WarehouseState of all items not stored in the Atlanta, Bangor, or Chicago warehouse. Use the NOT IN keyword.
2.44) Write a SQL statement to produce a single column called ItemLocation that combines the SKU_Description, the phrase “is located in,” and WarehouseCity. Do not be concerned with removing leading or trailing blanks.
2.45) Write a SQL statement to show the SKU, SKU_Description, and WarehouseID for all items stored in a warehouse managed by ‘Lucille Smith’. Use a subquery.
2.46) Write a SQL statement to show the SKU, SKU_Description, and WarehouseID for all items stored in a warehouse managed by ‘Lucille Smith’. Use a join, but do not use JOIN ON syntax.
2.47) Write a SQL statement to show the SKU, SKU_Description, and WarehouseID for all items stored in a warehouse managed by ‘Lucille Smith’. Use a join using JOIN ON syntax.
2.48) Write a SQL statement to show the WarehouseID and average QuantityOnHand of all items stored in a warehouse managed by ‘Lucille Smith’. Use a subquery.
2.49) Write a SQL statement to show the WarehouseID and average QuantityOnHand of all items stored in a warehouse managed by ‘Lucille Smith’. Use a join, but do not use JOIN ON syntax.
2.50) Write a SQL statement to show the WarehouseID and average QuantityOnHand of all items stored in a warehouse managed by ‘Lucille Smith’. Use a join using JOIN ON syntax.
2.51) Write a SQL statement to show the WarehouseID, WarehouseCity, WarehouseState, Manager, SKU, SKU_Description, and QuantityOnHand of all items stored in a warehouse managed by ‘Lucille Smith’. Use a join using JOIN ON syntax.
2.52) Write a SQL statement to display the WarehouseID, the sum of QuantityOnOrder, and the sum of QuantityOnHand, grouped by WarehouseID and QuantityOnOrder. Name the sum of QuantityOnOrder as TotalItemsOnOrder and the sum of Quantity OnHand as TotalItemsOnHand. Use only the INVENTORY table in your SQL statement.
2.53) Explain why you cannot use a subquery in your answer to Review Question 2.52.
2.54) Explain how subqueries and joins differ.
2.55) Write a SQL statement to join WAREHOUSE and INVENTORY and include all rows of WAREHOUSE in your answer, regardless of whether they have any INVENTORY. Include all columns of both tables, but do not repeat the join column.
2.56) Write a SQL statement to display the SKU, SKU_Description, and Department of all SKUs that appear in either the Cape Codd 2016 catalog (either in the printed catalog or on the Web site) or the Cape Codd 2017 catalog (either in the printed catalog or on the Web site) or both.
2.57) Write a SQL statement to display the SKU, SKU_Description, and Department of all SKUs that appear in either the Cape Codd 2016 catalog (only in the printed catalog itself) or the Cape Codd 2017 catalog (only in the printed catalog itself) or both.
2.58) Write a SQL statement to display the SKU, SKU_Description, and Department of all SKUs that appear in both the Cape Codd 2016 catalog (either in the printed catalog or on the Web site) and the Cape Codd 2017 catalog (either in the printed catalog or on the Web site).
2.59) Write a SQL statement to display the SKU, SKU_Description, and Department of all SKUs that appear in both the Cape Codd 2016 catalog (only in the printed catalog itself) and the Cape Codd 2017 catalog (only in the printed catalog itself).
2.60) Write a SQL statement to display the SKU, SKU_Description, and Department of all SKUs that appear in only the Cape Codd 2016 catalog (either in the printed catalog or on the Web site) and not in the Cape Codd 2017 catalog (either in the printed catalog or on the Web site).
2.61) Suppose that I consider changing the primary key of SKU_DATA table to “Buyer”. Write correlated subqueries to display any data that indicates that this change is not justifiable.