Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Question 11 / 11

Consider an Orders table which has 15 years of historical orders and you are loading everyday incremental orders into it on a daily basis(1 million orders per day are loaded and historically the full orders is close to a billion orders). The orders table is range partitioned on order_day.

ORDERS ----------ORDER_ID ORDER_DAY CUSTOMER_ID ADDRESS_ID ITEM_ID PRICE QUANTITY

ORDERS_DAILY_INCREMENT ---------------SNAPSHOT_DAY ORDER_ID ORDER_DAY CUSTOMER_ID ADDRESS_ID ITEM_ID PRICE QUANTITY If you are asked to build a daily aggregate table like the one shown below with "new_customer" metric and "reactivated_customer" metric(a reactivated customer is the

one who did not have a purchase in the last one year but made a purchase today) on each day CUSTOMER_AGGREGATE ---------------------------------SNAPSHOT_DAY NEW_CUSTOMERS REACTIVATED_CUSTOMERS Would you build any interim tables to support this requirement ? if yes, why and what would they look like along with SQLs that you would use on ORDERS and ORDERS_DAILY_INCREMENT table to build those interim tables if no, why not and please provide the SQL that you would use to build the final CUSTOMER_AGGREGATE table using ORDERS and ORDERS_DAILY_INCREMENT

Question 10 / 11

Consider a Phone Log table as below. It records all phone numbers that we dial in a given day. SOURCE_PHONE_NUMBER DESTINATION_PHONE_NUMBER CALL_START_DATETIME 1234 4567 01/07/2011 10:00 1234 2345 01/07/2011 11:00 1234 3456 01/07/2011 12:00 1234 3456 01/07/2011 13:00 1234 4567 01/07/2011 15:00 1222 7890 01/07/2011 10:00 1222 7680 01/07/2011 12:00 1222 2345 01/07/2011 13:00

Please provide an SQL query to display the source_phone_number and a flag where the flag needs to be set to Y if first called number and last called number are the same and N if the first called number and last called number are different.

Desired Output: Source Number 1222 1234 Is_Match N Y

Product Dimension Table: PRODUCT_ID P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 PRODUCT_GROUP Book Book Electronics Electronics Electronics Video DVD Video DVD Video DVD Video DVD Shoes Shoes Shoes Shoes Book Book PRODUCT_NAME Harry Potter 1 Harry Potter 2 Nikon 10 MPS Cannon 8 MPS Cannon 10 MPS Pirates 1 Pirates 2 HP 1 HP 2 Nike 10 Nike 11 Adidas 10 Adidas 09 God Father 1 God Father 2

Sales_fact Table: SNAPSHOT_DAY PRODUCT_ID SALES_AMT

20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11

P1 P2 P8 P3 P4 P5 P6 P7 P9 P10 P11

10 5 100 5 25 15 35 5 30 8 45

Glance View Fact Table: SNAPSHOT_DAY 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 PRODUCT_ID P1 P2 P8 P3 P4 P5 P6 P7 P9 P10 P12 P13 P14 GLANCE_VIEWS 1000 800 700 800 500 250 10 1000 1500 600 670 300 230

Inventory Fact Table:

SNAPSHOT_DAY 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11

PRODUCT_ID P1 P2 P8 P3 P4

ON_HAND_QUANTITY 100 70 90 10 30

20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11

P5 P6 P7 P9

100 120 70 90

Ad_spend_fact Table:

SNAPSHOT_DAY 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11

PRODUCT_ID P1 P2 P8 P3 P4 P5 P6 P7 P9 P10 P11

GLANCE_VIEWS 10 5 100 5 25 15 35 5 30 8 45

Write a SQL that will give the top product by sales in each of the product groups and additionally gather GV, Inventory, and ad spend measures also for the product. Desired Output: Book Electronics Shoes Video DVD P1 P4 P11 P8 10 25 45 100 1000 500 0 700 100 30 0 90 0 30 0 0

Product Dimension Table: PRODUCT_ID PRODUCT_GROUP PRODUCT_NAME P1 Book Harry Potter 1 P2 Book Harry Potter 2

P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15

Electronics Electronics Electronics Video DVD Video DVD Video DVD Video DVD Shoes Shoes Shoes Shoes Book Book

Nikon 10 MPS Cannon 8 MPS Cannon 10 MPS Pirates 1 Pirates 2 HP 1 HP 2 Nike 10 Nike 11 Adidas 10 Adidas 09 God Father 1 God Father 2

Sales_fact Table: SNAPSHOT_DAY PRODUCT_ID SALES_AMT 20-JUL-11 P1 10 20-JUL-11 P2 5 20-JUL-11 P8 100 20-JUL-11 P3 5 20-JUL-11 P4 25 20-JUL-11 P5 15 20-JUL-11 P6 35 20-JUL-11 P7 5 20-JUL-11 P9 30 20-JUL-11 P10 8 20-JUL-11 P11 45

Glance View Fact Table: SNAPSHOT_DAY PRODUCT_ID GLANCE_VIEWS 20-JUL-11 P1 1000 20-JUL-11 P2 800 20-JUL-11 P8 700 20-JUL-11 P3 800 20-JUL-11 P4 500 20-JUL-11 P5 250

20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11

P6 P7 P9 P10 P12 P13 P14

10 1000 1500 600 670 300 230

Inventory Fact Table:

SNAPSHOT_DAY PRODUCT_ID ON_HAND_QUANTITY 20-JUL-11 P1 100 20-JUL-11 P2 70 20-JUL-11 P8 90 20-JUL-11 P3 10 20-JUL-11 P4 30 20-JUL-11 P5 100 20-JUL-11 P6 120 20-JUL-11 P7 70 20-JUL-11 P9 90

Ad_spend_fact Table:

SNAPSHOT_DAY PRODUCT_ID GLANCE_VIEWS 20-JUL-11 P1 10 20-JUL-11 P2 5 20-JUL-11 P8 100 20-JUL-11 P3 5 20-JUL-11 P4 25 20-JUL-11 P5 15 20-JUL-11 P6 35 20-JUL-11 P7 5 20-JUL-11 P9 30 20-JUL-11 P10 8 20-JUL-11 P11 45

For the table structures as above, write a SQL to give all Products that have glance views but no sales. Desired Output: P12 P13 P14

Product Dimension Table: PRODUCT_ID PRODUCT_GROUP PRODUCT_NAME P1 Book Harry Potter 1 P2 Book Harry Potter 2 P3 Electronics Nikon 10 MPS P4 Electronics Cannon 8 MPS P5 Electronics Cannon 10 MPS P6 Video DVD Pirates 1 P7 Video DVD Pirates 2 P8 Video DVD HP 1 P9 Video DVD HP 2 P10 Shoes Nike 10 P11 Shoes Nike 11 P12 Shoes Adidas 10 P13 Shoes Adidas 09 P14 Book God Father 1 P15 Book God Father 2

Sales_fact Table: SNAPSHOT_DAY PRODUCT_ID SALES_AMT 20-JUL-11 P1 10 20-JUL-11 P2 5 20-JUL-11 P8 100 20-JUL-11 P3 5 20-JUL-11 P4 25 20-JUL-11 P5 15 20-JUL-11 P6 35

20-JUL-11 20-JUL-11 20-JUL-11 20-JUL-11

P7 P9 P10 P11

5 30 8 45

Glance View Fact Table: SNAPSHOT_DAY PRODUCT_ID GLANCE_VIEWS 20-JUL-11 P1 1000 20-JUL-11 P2 800 20-JUL-11 P8 700 20-JUL-11 P3 800 20-JUL-11 P4 500 20-JUL-11 P5 250 20-JUL-11 P6 10 20-JUL-11 P7 1000 20-JUL-11 P9 1500 20-JUL-11 P10 600 20-JUL-11 P12 670 20-JUL-11 P13 300 20-JUL-11 P14 230

Inventory Fact Table:

SNAPSHOT_DAY PRODUCT_ID ON_HAND_QUANTITY 20-JUL-11 P1 100 20-JUL-11 P2 70 20-JUL-11 P8 90 20-JUL-11 P3 10 20-JUL-11 P4 30 20-JUL-11 P5 100 20-JUL-11 P6 120 20-JUL-11 P7 70 20-JUL-11 P9 90

Ad_spend_fact Table:

SNAPSHOT_DAY PRODUCT_ID GLANCE_VIEWS 20-JUL-11 P1 10 20-JUL-11 P2 5 20-JUL-11 P8 100 20-JUL-11 P3 5 20-JUL-11 P4 25 20-JUL-11 P5 15 20-JUL-11 P6 35 20-JUL-11 P7 5 20-JUL-11 P9 30 20-JUL-11 P10 8 20-JUL-11 P11 45

For the same above table structure, Write a SQL to give the sales of Electronics as a Percentage of Books Desired Output:

You might also like