What is the SQL command to list the number of product sales (number of rows) and total sales by month and product category, with subtotals by month and product category and a grand total for all sales? Figure P13.10 shows the result of the query.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Instructions

Using the data provided in the Ch13_SaleCo; database, solve the following problems.
(Hint: In Problems 5–11, use the ROLLUP command.)

Below is the Schema for the database:

Problem 10

What is the SQL command to list the number of product sales (number of rows) and total sales by month and product category, with subtotals by month and product category and a grand total for all sales? Figure P13.10 shows the result of the query.

**Figure 13.20: SALECO Snowflake Schema**

This diagram illustrates the SALECO snowflake schema used in data warehousing. Below is a detailed breakdown of each entity and its relationships:

### Entities and Attributes:

1. **DWREGION**
   - **Primary Key (PK):** REG_ID
   - **Attributes:**
     - REG_NAME

2. **DWTIME**
   - **Primary Key (PK):** TM_ID
   - **Attributes:**
     - TM_YEAR
     - TM_MONTH
     - TM_DAY
     - TM_QTR

3. **DWVENDOR**
   - **Primary Key (PK):** V_CODE
   - **Attributes:**
     - V_NAME
     - V_AREACODE
     - V_STATE

4. **DWCUSTOMER**
   - **Primary Key (PK):** CUS_CODE
   - **Attributes:**
     - CUS_LNAME
     - CUS_FNAME
     - CUS_INITIAL
     - CUS_STATE
   - **Foreign Key (FK1):** REG_ID

5. **DWPRODUCT**
   - **Primary Key (PK):** P_CODE
   - **Attributes:**
     - P_DESCRIPT
     - P_CATEGORY
   - **Foreign Key (FK1):** V_CODE

6. **DWSALESFACT**
   - **Primary Keys (PK, FK2, FK1, FK3):** TM_ID, CUS_CODE, P_CODE
   - **Attributes:**
     - SALE_UNITS
     - SALE_PRICE

### Relationships:

- **DWREGION** is related to **DWCUSTOMER** via REG_ID.
- **DWCUSTOMER**, **DWPRODUCT**, and **DWTIME** connect to **DWSALESFACT** through their respective foreign keys.
- **DWVENDOR** is connected to **DWPRODUCT** with V_CODE acting as a foreign key in DWPRODUCT.

The schema represents a more normalized variant of a star schema, with an emphasis on eliminating data redundancy by organizing data into multiple related tables.
Transcribed Image Text:**Figure 13.20: SALECO Snowflake Schema** This diagram illustrates the SALECO snowflake schema used in data warehousing. Below is a detailed breakdown of each entity and its relationships: ### Entities and Attributes: 1. **DWREGION** - **Primary Key (PK):** REG_ID - **Attributes:** - REG_NAME 2. **DWTIME** - **Primary Key (PK):** TM_ID - **Attributes:** - TM_YEAR - TM_MONTH - TM_DAY - TM_QTR 3. **DWVENDOR** - **Primary Key (PK):** V_CODE - **Attributes:** - V_NAME - V_AREACODE - V_STATE 4. **DWCUSTOMER** - **Primary Key (PK):** CUS_CODE - **Attributes:** - CUS_LNAME - CUS_FNAME - CUS_INITIAL - CUS_STATE - **Foreign Key (FK1):** REG_ID 5. **DWPRODUCT** - **Primary Key (PK):** P_CODE - **Attributes:** - P_DESCRIPT - P_CATEGORY - **Foreign Key (FK1):** V_CODE 6. **DWSALESFACT** - **Primary Keys (PK, FK2, FK1, FK3):** TM_ID, CUS_CODE, P_CODE - **Attributes:** - SALE_UNITS - SALE_PRICE ### Relationships: - **DWREGION** is related to **DWCUSTOMER** via REG_ID. - **DWCUSTOMER**, **DWPRODUCT**, and **DWTIME** connect to **DWSALESFACT** through their respective foreign keys. - **DWVENDOR** is connected to **DWPRODUCT** with V_CODE acting as a foreign key in DWPRODUCT. The schema represents a more normalized variant of a star schema, with an emphasis on eliminating data redundancy by organizing data into multiple related tables.
The table represents sales data categorized by month and product category. It contains four columns: TM_MONTH, P_CATEGORY, NUMPROD, and TOTSALES.

**Columns Explained:**

- **TM_MONTH**: Indicates the month number (9 or 10, with NULL representing an aggregate of all months).
- **P_CATEGORY**: The product category, labeled as CAT1, CAT2, CAT3, CAT4, or NULL for uncategorized products.
- **NUMPROD**: The number of products sold in the respective category and month.
- **TOTSALES**: The total sales in monetary value for the products sold.

**Data Analysis:**

1. **For Month 9:**
   - Category CAT1 sold 8 products totaling $174.83.
   - Category CAT2 sold 4 products totaling $446.81.
   - Category CAT3 sold 5 products totaling $537.54.
   - Category CAT4 sold 6 products totaling $80.67.
   - Uncategorized products (NULL) accounted for 23 products and $1239.85.

2. **For Month 10:**
   - Category CAT1 sold 4 products totaling $124.89.
   - Category CAT2 sold 2 products totaling $366.91.
   - Category CAT3 sold 3 products totaling $459.64.
   - Category CAT4 sold 4 products totaling $60.77.
   - Uncategorized products (NULL) accounted for 13 products and $1012.21.

3. **Overall Totals:**
   - An overall number of 36 products recorded without specific categorization, totaling $2252.06.

This data can be used to analyze trends in product sales over time and determine the most lucrative product categories.
Transcribed Image Text:The table represents sales data categorized by month and product category. It contains four columns: TM_MONTH, P_CATEGORY, NUMPROD, and TOTSALES. **Columns Explained:** - **TM_MONTH**: Indicates the month number (9 or 10, with NULL representing an aggregate of all months). - **P_CATEGORY**: The product category, labeled as CAT1, CAT2, CAT3, CAT4, or NULL for uncategorized products. - **NUMPROD**: The number of products sold in the respective category and month. - **TOTSALES**: The total sales in monetary value for the products sold. **Data Analysis:** 1. **For Month 9:** - Category CAT1 sold 8 products totaling $174.83. - Category CAT2 sold 4 products totaling $446.81. - Category CAT3 sold 5 products totaling $537.54. - Category CAT4 sold 6 products totaling $80.67. - Uncategorized products (NULL) accounted for 23 products and $1239.85. 2. **For Month 10:** - Category CAT1 sold 4 products totaling $124.89. - Category CAT2 sold 2 products totaling $366.91. - Category CAT3 sold 3 products totaling $459.64. - Category CAT4 sold 4 products totaling $60.77. - Uncategorized products (NULL) accounted for 13 products and $1012.21. 3. **Overall Totals:** - An overall number of 36 products recorded without specific categorization, totaling $2252.06. This data can be used to analyze trends in product sales over time and determine the most lucrative product categories.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Intermediate SQL concepts
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education