> For the complete documentation index, see [llms.txt](https://vikram-bajaj.gitbook.io/cs-gy-6083-principles-of-database-systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vikram-bajaj.gitbook.io/cs-gy-6083-principles-of-database-systems/main-1/sql/advanced-sql/windowing.md).

# Windowing

Windowing is used to smooth out random variations.

It can be used to calculate moving averages.

```
select date, sum(value) over
(order by date between rows 1 preceding and 1 following)
from sales
```

Examples of other window specifications:

* **between rows unbounded preceding and current**
* **rows unbounded preceding**
* **range between 10 preceding and current row**
  * all rows with values between current row value –10 to current value
* **range interval 10 day preceding**
  * not including current row
