0% found this document useful (0 votes)
5 views

Course2Module4Assignment

The Module 4 assignment focuses on practicing SQL statements for data integration using Oracle and PostgreSQL. It includes various problems that require writing MERGE, INSERT ALL, and INSERT FIRST statements to manipulate data across multiple tables. Students are encouraged to use both database management systems and justify their solutions with execution results where applicable.

Uploaded by

Senti singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Course2Module4Assignment

The Module 4 assignment focuses on practicing SQL statements for data integration using Oracle and PostgreSQL. It includes various problems that require writing MERGE, INSERT ALL, and INSERT FIRST statements to manipulate data across multiple tables. Students are encouraged to use both database management systems and justify their solutions with execution results where applicable.

Uploaded by

Senti singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Module 4 Assignment

SQL Statements for Data Integration


The Module 4 assignment provides practice with SQL statements for data integration. A

file in the same website item contains table definitions for the problems. Problems 1 to 9 involve

Oracle SQL for the MERGE and multiple table INSERT statements. Problems 10 to 12 involve

the INSERT … ON CONFLICT statement for PostgreSQL. You are encouraged to use both

DBMSs to complete the assignment. If you only have one DBMS installed, you should provide

your best solution without execution for statements using the other DBMS.

1. Write an Oracle SQL MERGE statement to combine the SSItem dimension table and the

SSItemChanges1 change table. The associated document contains CREATE TABLE and

INSERT statements for both tables. Each matching row of SSItemChanges1 contains values

for both modified and non-modified columns.

2. Write an Oracle SQL MERGE statement to combine the SSItem dimension table and the

SSItemChanges2 change table. The associated document contains CREATE TABLE and

INSERT statements for both tables. Each matching row of SSItemChanges2 contains new

values for modified columns and null values for non-modified columns.

3. Write an Oracle SQL INSERT ALL statement to insert rows of the ProductSale1 table into

four tables (ProductSales2018, ProductSales2019, ProductSales2020, and

ProductSales2021). The associated document contains CREATE TABLE and INSERT

statements for all tables. Note that the target tables lack the SalesYear column. If SalesYear

equals 2018, insert a row into ProductSales2018. The comparisons for the other tables only

differ on the SalesYear value and suffix in the name of the target table. You should compute

the SalesAmt column in each target table as the sum of the quarter sales (Qtr1, Qtr2, Qtr3,

and Qtr4) in the corresponding row of the ProductSale table.


12/10/2022 Module 4 Assignment on SQL Statements for Data Integration Page 2

4. On Problem 3, is the number of the rows in the target tables the same when using INSERT

FIRST versus INSERT ALL? Justify your answer by writing and executing an INSERT

FIRST statement.

5. Write an Oracle SQL INSERT FIRST statement to insert rows of the ProductSale2 table into

three target tables (Year_Low_Sales, Year_Mid_Sales, and Year_High_Sales). The associated

document contains CREATE TABLE statements for all tables. Insert a row into

Year_Low_Sales when annual sales (sum of Qtr1, Qtr2, Qtr3, and Qtr4) are less than 4,000.

Insert a row into Year_Mid_Sales when annual sales are greater than or equal 4,000 and less

than 7,000. Insert remaining rows into Year_High_Sales. You should compute the SalesAmt

column in each target table as the sum of the quarter sales (Qtr1, Qtr2, Qtr3, and Qtr4) in the

corresponding row of the ProductSale table.

6. On Problem 5, is the number of the rows in the target tables the same when using INSERT

FIRST versus INSERT ALL? Justify your answer by writing and executing an INSERT ALL

statement.

7. Write an Oracle MERGE statement to combine the Mobile_Bill table with the Mobile_Usage

table matching on CustId. The associated document contains CREATE TABLE statements

for both tables. The Mobile_Bill table contains the most recent bill with the current amount

(CurrentAmt) and past amount (PastAmt). When a match occurs, update the

Mobile_Bill.CurrentAmt column as minutes used (Mobile_Usage.MinutesUsed) times 0.05

and the Mobile_Bill.PastAmt column as the previous current amount

(Mobile_Bill.CurrentAmt) plus the previous past amount (Mobile_Bill.PastAmt). When a

match does not occur, insert a row into the Mobile_Bill table with the customer identifier
12/10/2022 Module 4 Assignment on SQL Statements for Data Integration Page 3

(Mobile_Usage.CustId), minutes used (Mobile_Usage.MinutesUsed) times 0.05, and 0 for

the past amount (Mobile_Bill.PastAmt).

8. Write an Oracle INSERT FIRST statement to insert rows from a mobile customer table

(Mobile_Customer) into three tables (Mobile_Gold, Mobile_Silver, and Mobile_Bronze)

based on a customer’s current revenue amount (Mobile_Customer.CurrentAmt). The

associated document contains CREATE TABLE statements for all tables. If the current

revenue amount is greater than or equal to 150, insert the mobile customer row into the

Mobile_Gold table. If the current revenue amount is greater than or equal to 100, insert the

mobile customer row into the Mobile_Silver table. Otherwise, insert the mobile customer row

into the Mobile_Bronze table.

9. On Problem 8, is the number of the rows in the target tables the same when using INSERT

FIRST versus INSERT ALL? Justify your answer by writing and executing an INSERT ALL

statement.

10. Write a PostgreSQL INSERT …. CONFLICT ON statement for the requirements in Problem

1.

11. Write a PostgreSQL INSERT …. CONFLICT ON statement for the requirements in Problem

2.

12. Modify the solution to Problem 11 to work with NOT NULL constraints on all columns of

SSItem except for ItemId. INSERT statements have been modified in the change table in the

associated document. Text columns (VARCHAR and CHAR) have a value of “NV” for no

value. Numeric columns have a value of 0 for no value. For this problem, you should study

the extended example for the last PostgreSQL slide (slide 11). The extended example is only
12/10/2022 Module 4 Assignment on SQL Statements for Data Integration Page 4

contained the file with Lesson 7 examples. This slide document does not contain this

example.

You might also like