
You are given a customer profile table from Best Buy account data. Some records are incomplete or inconsistent: email may be missing, phone may be blank, city may be null, and loyalty tier values may not follow the expected standard. Write a PostgreSQL query that returns one row per customer_id with a data_quality_status of Complete, Incomplete, or Inconsistent. Treat a record as Incomplete if email, phone, or city is null or an empty string. Treat a record as Inconsistent if loyalty_tier is not one of My Best Buy, My Best Buy Plus, or My Best Buy Total. If both issues exist, label the record as Inconsistent. Return the results ordered by customer_id.
| column | type | description |
|---|---|---|
| customer_id | INT | Unique customer identifier |
| full_name | VARCHAR(100) | Customer full name |
| VARCHAR(150) | Customer email address | |
| phone | VARCHAR(20) | Customer phone number |
| city | VARCHAR(100) | Customer city |
| loyalty_tier | VARCHAR(50) | Best Buy loyalty membership tier |
| customer_id | full_name | phone | city | loyalty_tier | |
|---|---|---|---|---|---|
| 104 | Mia Chen | mia.chen@example.com | Seattle | My Best Buy | |
| 101 | Ava Patel | ava.patel@example.com | 612-555-0182 | Minneapolis | My Best Buy |
| 106 | Noah Kim | noah.kim@example.com | 773-555-0101 | Chicago | Elite |
| customer_id | data_quality_status |
|---|---|
| 101 | Complete |
| 102 | Incomplete |
| 103 | Incomplete |
| 104 | Incomplete |
| 105 | Incomplete |
| 106 | Inconsistent |
| 107 | Inconsistent |
| 108 | Complete |
| 109 | Incomplete |
| 110 | Inconsistent |
| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| full_name | VARCHAR(100) | Customer full name |
| VARCHAR(150) | Customer email address | |
| phone | VARCHAR(20) | Customer phone number |
| city | VARCHAR(100) | Customer city |
| loyalty_tier | VARCHAR(50) | Best Buy loyalty membership tier |
| customer_id | full_name | phone | city | loyalty_tier | |
|---|---|---|---|---|---|
| 104 | Mia Chen | mia.chen@example.com | Seattle | My Best Buy | |
| 101 | Ava Patel | ava.patel@example.com | 612-555-0182 | Minneapolis | My Best Buy |
| 109 | Lucas Reed | lucas.reed@example.com | 646-555-0199 | My Best Buy Plus | |
| 106 | Noah Kim | noah.kim@example.com | 773-555-0101 | Chicago | Elite |
| 103 | Sofia Martinez | 305-555-0122 | Miami | My Best Buy Total | |
| 108 | Ethan Brooks | ethan.brooks@example.com | 214-555-0177 | Dallas | My Best Buy Plus |
| 102 | Liam Johnson | 415-555-0110 | San Francisco | My Best Buy | |
| 110 | Grace Lee | Boston | |||
| 105 | Olivia Davis | olivia.davis@example.com | 206-555-0144 | My Best Buy Total | |
| 107 | Emma Wilson | emma.wilson@example.com | 404-555-0166 | Atlanta | |
| 1 | Chloe Nguyen | ava.patel@example.com | 718-555-0105 | null | Promo |
| 2 | Layla Ward | daniel.rivera@example.com | null | Denver | Premium |
| 3 | Grace Lee | noah.kim@example.com | 225-555-0195 | Nashville | Trial |
| 4 | Matthew Long | samuel.price@example.com | 404-555-0166 | Austin | null |
| 5 | Henry Foster | jack.cooper@example.com | 404-555-0166 | Columbus | Premium |
| 6 | Emma Wilson | emma.wilson@example.com | null | Salt Lake City | VIP |
| 7 | Nora Hughes | null | 214-555-0177 | New York | Gold |
| 8 | Nora Hughes | matthew.long@example.com | 919-555-0117 | Columbus | Gold |
| 9 | Ava Patel | harper.scott@example.com | 408-555-0108 | Dallas | null |
| 10 | Andrew Cox | victoria.ramirez@example.com | 305-555-0122 | Detroit | My Best Buy Total |
| 11 | Nora Hughes | scarlett.murphy@example.com | 303-555-0184 | Phoenix | Silver |
| 12 | Liam Johnson | samuel.price@example.com | 602-555-0138 | Houston | Trial |
| 13 | Layla Ward | harper.scott@example.com | 901-555-0169 | null | null |
| 14 | Lucas Reed | samuel.price@example.com | 312-555-0149 | Los Angeles | |
| 15 | Liam Johnson | zoe.bennett@example.com | 408-555-0108 | Phoenix | Elite |
| customer_id | data_quality_status |
|---|---|
| 1 | Inconsistent |
| 2 | Inconsistent |
| 3 | Inconsistent |
| 4 | Inconsistent |
| 5 | Inconsistent |
| 6 | Inconsistent |
| 7 | Inconsistent |
| 8 | Inconsistent |
| 9 | Inconsistent |
| 10 | Complete |
| 11 | Inconsistent |
| 12 | Inconsistent |
| 13 | Inconsistent |
| 14 | Inconsistent |
| 15 | Inconsistent |
| 101 | Complete |
| 102 | Incomplete |
| 103 | Incomplete |
| 104 | Incomplete |
| 105 | Incomplete |
| 106 | Inconsistent |
| 107 | Inconsistent |
| 108 | Complete |
| 109 | Incomplete |
| 110 | Inconsistent |