• So how exactly does one "aggregate (...) those rows that had been processed BEFORE the current row" with LAG?

    (I emphasized two important words in that quote from the question - rows is plural and aggregate suggests aggregating multiple rows into one result).

    I picked PREVIOUS, thinking that the author had misspelled PRECEDING, which would have been the only correct answer to this question.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/