What are window functions in SQL, and how would you use them to calculate a rolling average of account balances for Hsbc?
Use the account_balances table and calculate the average balance for each account across the current record and its two preceding records.
account_id, balance_date, balance, and rolling_avg_balance.account_id, then balance_date.| Column | Type | Description |
|---|---|---|
| balance_idPK | INT | Unique balance observation identifier |
| account_id | VARCHAR(20) | Hsbc customer account identifier |
| balance_date | DATE | Date of the balance observation |
| balance | DECIMAL(12,2) | Account balance on the observation date |