LAG() are always relative to the current row. Now we'll get to know three other functions that are independent of the current row.
The first one is
FIRST_VALUE(x). As you may guess, it returns the first value in the column x in the given order. Take a look:
FIRST_VALUE(Budget) OVER(ORDER BY OpenDate ASC) AS FirstBudget
In this query, we are still sorting rows by the opening date (
ORDER BY OpenDate ASC), but we are showing the budget for the earliest opening date (
FIRST_VALUE(budget)). In this way, we can show the budget for the website that was opened first.
Note that this would be impossible to achieve with a simple
MIN(budget) would simply show the smallest budget (500 in this case). That is not the same as the budget of the first website (3000)!