Capital One's card analytics team wants to monitor monthly spending volume per cardholder across its credit card portfolio. Write a PostgreSQL query that calculates the month-over-month change in the average monthly transaction volume.
Assume transaction volume means the sum of posted purchase amounts for each cardholder during a calendar month. Include only cardholders with at least one qualifying transaction in that month. Exclude pending transactions, refunds, and transactions with a NULL amount.
Requirements
- Join cardholders, cards, and transactions to associate each transaction with its cardholder.
- Aggregate transaction volume first at the cardholder-month level.
- Calculate the average cardholder volume for each month.
- Use
LAG to calculate the month-over-month percentage change, returning NULL for the first month.
- Round average volume and percentage change to two decimal places and order results chronologically.