您的位置:首页 > 数据库

sql server 迭代

2011-03-31 20:36 127 查看
if exists (select * from sysobjects where id = OBJECT_ID('[test]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)

DROP TABLE [test]

CREATE TABLE [test] (

[id] [nchar] (10) NULL,

[A] [int] NULL,

[B] [int] NULL)

INSERT [test] ([id],[A],[B]) VALUES ( '1',1,2)

INSERT [test] ([id],[A],[B]) VALUES ( '2',3,4)

INSERT [test] ([id],[A],[B]) VALUES ( '3',5,6)

INSERT [test] ([id],[A],[B]) VALUES ( '4',7,8)

INSERT [test] ([id],[A],[B]) VALUES ( '5',9,10)

INSERT [test] ([id],[A],[B]) VALUES ( '6',11,12)

SELECT a.id ,A,B ,

(SELECT SUM(A+B)FROM test b where b.id<=a.id) as total

FROM test a



更多参考 http://www.cio360.net/h/2253/348611-9313.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息