Tell me about the most difficult questions you faced in the SQL round, especially those involving window functions.
For this exercise, write a PostgreSQL query that demonstrates this type of analysis using the provided account transaction data. Include only posted transactions from the first quarter of 2025.
Output
- One row per included transaction, with
account_id, transaction_id, transaction_date, amount, prior_amount, running_balance, and three_transaction_average
prior_amount is the previous posted transaction amount for that account; cumulative and average values are calculated chronologically
- Order by
account_id, transaction_date, and transaction_id
Output details
- Interpret posted transactions as rows whose status equals
posted.
- Use an inclusive lower bound of
2025-01-01 and an exclusive upper bound of 2025-04-01.
- Sort
account_id, transaction_date, and transaction_id in ascending order.
- Round
three_transaction_average to two decimal places.
- Treat NULL amounts as zero for
running_balance, but ignore them when calculating three_transaction_average.
- Include only transactions having matching account and transaction-type records.