Daily revenue figures fluctuate due to weekends, promotions, and seasonality. A rolling 7-day revenue total smooths out those spikes and gives finance a stable trend line to track. Using the orders table, return order_date, daily_revenue, and rolling_7d_revenue (sum of daily_revenue over the current day and the 6 preceding days), ordered by order_date.
orders
| column | type |
|---|---|
| id | INTEGER |
| customer_id | INTEGER |
| amount | NUMERIC |
| created_at | DATE |
orders
| id | customer_id | amount | created_at |
|---|---|---|---|
| 1 | 1 | 100.00 | 2024-01-01 |
| 2 | 2 | 150.00 | 2024-01-02 |
| 3 | 1 | 200.00 | 2024-01-03 |
| 4 | 3 | 50.00 | 2024-01-04 |
| 5 | 2 | 175.00 | 2024-01-05 |
| 6 | 1 | 225.00 | 2024-01-06 |
| 7 | 3 | 300.00 | 2024-01-07 |
| 8 | 1 | 125.00 | 2024-01-08 |
| 9 | 2 | 250.00 | 2024-01-09 |
| 10 | 3 | 75.00 | 2024-01-10 |
| order_date | daily_revenue | rolling_7d_revenue |
|---|---|---|
| 2024-01-01 | 100.00 | 100.00 |
| 2024-01-02 | 150.00 | 250.00 |
| 2024-01-03 | 200.00 | 450.00 |
| 2024-01-04 | 50.00 | 500.00 |
| 2024-01-05 | 175.00 | 675.00 |
| 2024-01-06 | 225.00 | 900.00 |
| 2024-01-07 | 300.00 | 1200.00 |
| 2024-01-08 | 125.00 | 1225.00 |
| 2024-01-09 | 250.00 | 1325.00 |
| 2024-01-10 | 75.00 | 1200.00 |
Days 1–7 accumulate the full 7-day window as it grows. From day 8 onward the window is always exactly 7 days: day 8's rolling total drops day 1 (100) and adds day 8 (125), giving 1200 + 125 − 100 = 1225.