have a table like below where I have to take sum of col2 based on group by. But it belongs to a chain, if chain breaks then sum will be limited to sequence.
DECLARE @TabVar TABLE
(
ID INT IDENTITY(1,1), col1 varchar(20), Col2 INT
)
INSERT INTO @TabVar
VALUES ('a',2),('a',3),('b',4),('b',2),('a',6),('a',3),('b',3)
SELECT * FROM @TabVar
Expected output:
COL1 SUM(COL2)
A 5
B 6
A 9
B 3
I have tried to do it with Ranking functions but ranking is done using Order by which accumulate total of Col1