我有一个有两列的临时表
create table temp
(
id int identity(1,1),
amount decimal(18,2)
)
样本数据插入如下
insert into temp(credit)
values (100), (200), (500)
这张桌子看起来像
id amount
-----------
1 100
2 200
3 500
我试图实现的是,如果我们从表中扣除150,那么扣除应该按照Id的顺序进行.这意味着Id 1的金额将为0(100-150=0,剩余为50),然后Id 2的金额将为150(之前扣除的余额50必须从200减少)
所以结果数据集应该是
id amount
---------
1 0
2 150
3 500