Hulu | Walt Disney | Senior Data Engineer Data Modeling Interview
Anonymous User
1930

Company : Walt Disney | Hulu
Role : Senior Data Engineer
YOE: 10 yrs

Question:

Build a simple data model to track information about an online store.
In this store, customers may purchase items at any time. Also, they can pay their total order
amount in multiple payments up to their discretion.

John: Jan 1st, Purchases a total of 6
Qty 20 DrZeus Chocolates $2

Jan 1st → Paid 40

Solution :


Customer: 
cust_id 

Order:
order_id
order_date
cust_id
order_price
order_status


Order_Product:
order_id
product_id
product_qunty

Products:
product_id
product_price

Payment:
payment_id
payment_date
cust_id
payment_amount
payment_status






1. top 5 cust amount owed

With payment_received as (
    select cust_id, sum(payment_amount) over() total_payment_received from Payment where payment_status = 'success' group by cust_id
),
payment_owed as ( 
    select cust_id, sum(order_price) over() total_payment_owed from Order where order_status = 'success' group by cust_id
)

payment_balance as (
    select pr.cust_id,  (total_payment_owed - total_payment_received)  as  payment_balance, dense_rank() over(order by payment_balance desc) rank from payment_received pr join payment_owed po on pr.cust_id = po.cust_id
)
select cust_id, payment_balance from payment_balance where rank <=3





Comments (1)