Write a SQL query to calculate customer lifetime value by customer segment from transactional data. Treat lifetime value as the sum of completed transaction amounts for each customer. Include customers with no completed transactions, use Unspecified for missing segments, and exclude transactions belonging to unknown customers.
customer_segment, customer_count, total_lifetime_value, and average_lifetime_valuetotal_lifetime_value descending, then customer_segment ascending| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| segment | VARCHAR(40) | Customer segment |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| customer_id | INT | Customer associated with the transaction |
| amount | DECIMAL(12,2) | Transaction amount |
| status | VARCHAR(20) | Transaction processing status |