Aggregate adjacent only records with T-SQL

前端 未结 4 1825
孤街浪徒
孤街浪徒 2020-12-17 04:09

I have (simplified for the example) a table with the following data

Row Start       Finish       ID  Amount
--- ---------   ----------   --  ------
  1 2008-         


        
4条回答
  •  天涯浪人
    2020-12-17 04:45

    Probably need to create a cursor and loop through the results, keeping track of which id you are working with and accumulating the data along the way. When the id changes you can insert the accumulated data into a temporary table and return the table at the end of the procedure (select all from it). A table-based function might be better as you can then just insert into the return table as you go along.

提交回复
热议问题