D8LooPFocus modeCODE WORKSPACE
Return customer_id and load_action after deduping staged customer rows and comparing to the current dimension.
Start by naming the output grain, then build CTEs that can be inspected one at a time.
Sample input
| customer_id | stage_tier | target_tier | is_deleted |
|---|---|---|---|
| 101 | gold | silver | 0 |
| 103 | bronze | bronze | 1 |
| 104 | platinum | gold | 0 |
| 105 | bronze | bronze | 0 |
Expected output
| customer_id | load_action |
|---|---|
| 101 | update |
| 102 | insert |
| 103 | delete |
| 104 | update |
| 105 | unchanged |
| 106 | insert |
Constraints
State the output contract first, use readable CTE layers, return the exact columns requested by the prompt, and use deterministic ordering.
Expected skills
Interview clarification, SQL structure, edge-case handling, and final-answer narration.
Run the SQL query to inspect preview rows.