像这样的表:
Description Type Amount
Record 1 10
Record 2 20
Record 1 5
Record 3 10
如何在我的运行总和中排除某种类型的记录?因此,如果我排除类型 3,我的运行总和变为:
Description Type Amount RunningSum
Record 1 10 10
Record 2 20 30
Record 1 5 35
我正在使用更新局部变量技术。我有的:
DECLARE @Amount DECIMAL(18, 4)
SET @Amount = 0
UPDATE MY_TABLE
SET RunningTotal = @Amount
,@Amount = @Amount + ISNULL(Amount, 0)