Explain how you would use SQL to extract actionable insights from a messy, multi-source dataset.
Use the provided customer, sales order, and support ticket tables. Consider inconsistent status values, missing amounts, unmatched source records, inactive customers, and customers with no activity.
Output
- One row per active customer.
- Include
customer_id, customer_name, region, total_revenue, completed_order_count, active_ticket_count, high_priority_active_tickets, last_order_date, and action_status.
- Include only orders from 2025-01-01 through 2025-03-31, include customers without matching orders or tickets, and sort by
total_revenue descending, then customer_id ascending.
Output details
- Treat a customer as active only when
active is TRUE.
- Normalize statuses, priorities, and order statuses by trimming whitespace and comparing case-insensitively.
- Count only normalized
completed orders; treat missing amounts as 0 for revenue.
- Treat normalized ticket statuses
open and pending as active, and count high priority only when normalized priority is high.
- Set
action_status to Escalate support for high-priority active tickets, Re-engage and resolve for zero revenue with active tickets, Prioritize account for revenue at least 500, otherwise Monitor.
- Retain every active customer-table row, including duplicate customer identifiers and NULL customer attributes.