You are given a month-end reporting workflow that currently relies on manual spreadsheet cleanup. Write a PostgreSQL query that returns each active account’s month-end billed amount for a chosen reporting month, using only posted transactions and excluding voided items. The result should be sorted by highest billed amount, then account name.
Output details
- Use
DATE '2024-05-01' as the reporting month and require that month to be closed.
- Return columns in order:
account_name, then month_end_billed_amount.
- Include transactions dated on or after
2024-05-01 and before 2024-06-01.
- Treat missing transaction totals as
0 and format billed amounts as numeric(12,2).
- Sort
month_end_billed_amount descending, then account_name ascending.