SQL Server 2012 Lag
and Lead
functions aren't performing well over large amounts of data, ~100 million records with ~200 columns.
The combination of
lag(balance, 1, 0) over (partition by loanId order by datetime series)
trying to get previous date's balance. The execution plan says most time consuming part falls in (order by) part.
Is there a way to improve the performance?