AArete's client analytics reporting workflow needs a smoother view of daily revenue from active client accounts. Write a PostgreSQL query that aggregates eligible transactions and calculates a rolling three-day average.
revenue_transactions to client_accounts and include only accounts with account_status = 'active'.daily_revenue, the total revenue for each transaction date.moving_avg_3_days: the average of the current date's revenue and the two preceding dates that have revenue (reporting dates, not calendar days). If fewer than three dates exist, average the available rows.moving_avg_3_days to two decimal places with ROUND(..., 2). Leave daily_revenue as the plain sum (amounts already have two decimals).revenue_date, daily_revenue, and moving_avg_3_days in ascending date order.| Column | Type | Description |
|---|---|---|
| account_idPK | INTEGER | Unique client account identifier |
| account_name | VARCHAR(100) | Client account name |
| account_status | VARCHAR(20) | Current account status |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INTEGER | Unique revenue transaction identifier |
| account_id | INTEGER | Client account associated with the transaction |
| revenue_date | DATE | Date on which revenue was recorded |
| revenue_amount | NUMERIC(12,2) | Revenue amount for the transaction |