How do you optimize a slow-running SQL join on tables containing millions of enterprise transaction records?
Use the supplied transaction, account, and event tables. Return only positive transactions from the first quarter of 2025 whose latest event before April 1, 2025 is SETTLED.
Output
- One row per account and transaction month
- Columns:
account_id, account_name, transaction_month, settled_transaction_count, and total_settled_amount
- Sort by
account_id, then transaction_month ascending
Output details
- Represent
transaction_month as the first calendar day of each month.
- When events share a transaction and timestamp, select the greatest
event_id as the latest event.
- Group results by
account_name in addition to account_id and transaction_month.