SQL排序算
auto_nomat_qtydec_qtyid_no
A000510000100001
B0001-50095002
C000115000245004
B0002-12000125003
B0003-500075005
B0004300045006
表格容及果如上dec_qty值上一dec_qty前mat_qty之和各位忙以下表格容要如何?
auto_nomat_qtydec_qtyid_no
A000510000100001
B0001-50095002
C000115000245004
B0002-12000125003
B0003-500075005
B0004300045006
[解决办法]
不吧
[解决办法]
--如果id_no有序的
--建境
Create Table 表
(auto_no Char(5),
mat_qty Int,
dec_qty Int,
id_no Int)
--插入
Insert 表 Select 'A0005 ',10000,0,1
Union All Select 'B0001 ',-500,0,2
Union All Select 'C0001 ',15000,0,4
Union All Select 'B0002 ',-12000,0,3
Union All Select 'B0003 ',-5000,0,5
Union All Select 'B0004 ',-3000,0,6
GO
--
--更新
Declare @dec_qty Int
Select @dec_qty = 0
Update 表 Set @dec_qty = @dec_qty + mat_qty, dec_qty = @dec_qty
Select * From 表
GO
--除境
Drop Table 表
--果
/*
auto_nomat_qtydec_qtyid_no
A000510000100001
B0001-50095002
C000115000245004
B0002-12000125003
B0003-500075005
B0004-300045006
*/