The JPMorganChase Data Analytics team needs a client-level summary of activity recorded across Chase client, account, and transaction tables. Write a PostgreSQL query for completed transactions during the first quarter of 2025.
Requirements
- Return every client, including clients with no qualifying account or transaction.
- Aggregate completed transaction count, total amount, and average amount per client. Treat NULL transaction amounts as zero for total and average calculations.
- Replace a missing client segment with
Unclassified.
- Sort by total completed amount descending, then
client_id ascending.
Output details
- Return columns named
client_id, client_name, client_segment, completed_transaction_count, total_completed_amount, and average_completed_amount, in that order.
- Interpret the first quarter as dates from
2025-01-01 inclusive through 2025-04-01 exclusive.
- Render total and average amounts as numeric values with exactly two decimal places, using
0.00 when no qualifying transactions exist.