# LAG

A window function returning a value from an earlier row in the window partition.

## What is **LAG** in a relational database?

**LAG** — A window function returning a value from an earlier row in the window partition.

```sql
SELECT ordered_on,
       LAG(total_amount) OVER (ORDER BY ordered_on) AS previous_total
FROM purchase_order;
```

Level: Journeyman · [More Database terms at this level](https://www.ask-codey.com/glossary/subjects/database/journeyman)

Updated: September 28, 2026

Source: https://www.ask-codey.com/glossary/lag
