EXL Service Philippines analysts need a daily sales metric for an operations reporting dashboard. Write a PostgreSQL query that calculates the running average of sales for the current day and the four preceding calendar days.
reporting_calendar, including dates with no transactions.daily_amount, treating missing transaction days as zero and ignoring NULL transaction amounts.five_day_running_avg using the current date and up to four preceding calendar dates.The window covers the current date and the 4 calendar days before it; a date that is not in reporting_calendar is simply absent from the window (the average is over the calendar dates present).
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| transaction_date | DATE | Date on which the transaction occurred |
| amount | NUMERIC(12,2) | Sales amount for the transaction |
| Column | Type | Description |
|---|---|---|
| calendar_datePK | DATE | Calendar date required in the report |