Course 3 Module 2 Assignment
Course 3 Module 2 Assignment
The Module 2 Assignment provides experience writing SELECT statements using the
subtotal operators (CUBE, ROLLUP, and GROUPING SETS). You should follow the examples
Your SELECT statements will reference the tables of the Inventory Data Warehouse,
described in another document. The INSERT statements are provided in another document. The
Inventory Data Warehouse design and rows are identical from module 5 in course 2. If you
added rows through the data integration assignment in module 5 of course 2, you should remove
Write an SQL statement to display the sum of the extended cost and the sum of the quantity. The
results should include data for shipments (transaction type 5) in calendar year 2021. Summarize
the result by calendar month and Address Category Code 1. The result should include the
grouped columns and the full totals for every combination of grouped columns. Do not use the
GROUPING SETS and UNION operators.
Write an SQL statement to display the sum of the extended cost and the number of inventory
transactions. The results should include data for shipments (transaction type 5) in calendar years
2021 and 2022. Summarize the result by calendar quarter, customer zip code, and customer
name. The result should include the grouped columns and full set of subtotals for every
combination of grouped columns. Do not use the CUBE and UNION operators.
Write an SQL statement to display the sum of the extended cost and the sum of the quantity. The
results should include data for transfers (transaction type 2). Summarize the result by company
name and branch plant name. The result should include the grouped columns and a partial set of
subtotals in order of the grouped columns (company name and branch plant name). Transfer
quantities by design should sum to zero across all companies so that the grand total should be 0
for the sum of quantity and extended cost. Do not use the GROUPING SETS and UNION
operators.
3/22/2023 Module 2 Assignment Page 2
Write an SQL statement to display the sum of the extended cost and the number of inventory
transactions. The results should include data for all transaction types. Summarize the result by
transaction description, company name, and branch plant name. The result should include the
grouped columns and partial totals in order of the grouped columns (transaction description,
company name, and branch plant name). Do not use the ROLLUP and UNION operators.
Write an SQL statement to display the sum of the extended cost and the number of inventory
transactions. The results should include data for shipments (transaction type 5) in calendar years
2021 and 2022. Summarize the result by calendar year, calendar quarter, and customer name.
The result should show the grouped columns and the normal set of group by results plus partial
subtotals for year and quarter concatenated with customer name. Do not use the GROUPING
SETS and UNION operators. (Hint: see the partial ROLLUP example in lesson 5).
Rewrite query 1 without the usage of the CUBE ROLLUP, or GROUPING SETS operators. In
rewriting the query, you should use NULL as the default value for each column.
Rewrite query 3 without the usage of the CUBE, ROLLUP, or GROUPING SETS operators. In
rewriting the query, you should use NULL as the default value for each column.
Query 8: Sales Order Shipments by Name and Combination of Year and Quarter
Write an SQL statement to display the sum of the extended cost and the number of inventory
transactions. The results should include data for shipments (transaction type 5) in calendar years
2021 and 2022. Summarize the result by calendar year, calendar quarter, and customer name.
The result should include the grouped columns and the full set of subtotals for customer name
and the combination of year and quarter. Do not use the GROUPING SETS and UNION
operators. (Hint: see the composite column example in lesson 5).
Query 9: Sales Order Shipments by Month and Category Code1 with Group
Number
Write an SQL statement to display the sum of the extended cost and the sum of the quantity. The
results should include data for shipments (transaction type 5) in calendar year 2021. Summarize
the result by calendar month and Address Category Code 1. The result should include the
grouped columns and the full set of subtotals for every combination of grouped columns along
with the hierarchical group number for both grouping columns. Do not use the GROUPING
SETS and UNION operators. (Hint: see the group functions slide in lesson 5. In PostgreSQL, the
grouping identifier keyword is GROUPING, not GROUPING_ID as in Oracle).
3/22/2023 Module 2 Assignment Page 3
Query 10: Sales Order Shipments with Subtotals by Name and Partial Subtotals
by Year and Quarter
Write an SQL statement to display the sum of the extended cost and the number of inventory
transactions. The results should include data for shipments (transaction type 5) in calendar years
2021 and 2022. Summarize the result by calendar year, calendar quarter, and customer name.
The result should include the grouped columns and subtotals for customer name along with
partial subtotals for year and quarter. Do not include the normal GROUP BY totals in the result.
Do not use the UNION operator. (Hint: see the nested rollup example in lesson 5).
Grading
After finishing this assignment, you should evaluate your performance using the
assignment quiz and self-evaluation rubric. Before evaluation using the quiz and self-evaluation
rubric, you should create a document with a SELECT statement and snapshot of partial results
for each problem. You should not perform evaluation until each statement executes without
syntax errors. The quiz contains questions about elements of each problem such as the usage of
correct tables, join conditions, result columns, and other problem specific elements. Since some
quiz questions involve execution results, you should execute your statements using the original
inventory data warehouse tables. After completing the assignment quiz, you should apply the
self-evaluation rubric for a detailed review of each problem. You should use the reflective quiz