Customer Health
Part of the Connected Data section of Coddy's PostgreSQL journey. Lesson 25 of 25.
Challenge
HardReturn customer_id, name, paid_total, latest_paid_date and health for every customer. paid_total sums paid amounts with a zero fallback. latest_paid_date is the date of the newest paid order, breaking same-date ties by greater id, or NULL if none. health is no_paid_order when no paid order exists, high_value when paid_total is at least 60, and active otherwise. Order by paid_total descending then customer_id.
The input tables are shown in the test panel. Each run starts from fresh data. Return the named columns in the stated order; do not hard-code the displayed rows.
Try it yourself
-- Write your SQL here.
All lessons in Connected Data
Practice on your own: PostgreSQL playground