Sql server 2008 类似于跑步台的概念

Sql server 2008 类似于跑步台的概念,sql-server-2008,Sql Server 2008,我有一个表格,我想更新今天的期末余额,应该显示为箭头期初余额,如果期末余额的任何更新发生在特定日期,那么从该日期到当前日期的期初余额应该得到更新,以下是我想要的示例输出:;今天打开余额=昨天关闭余额 date opening_balance closing_balance accountformatid daybooktype 18-02-2013 12000 15000 1 240 19-02-20

我有一个表格,我想更新今天的期末余额,应该显示为箭头期初余额,如果期末余额的任何更新发生在特定日期,那么从该日期到当前日期的期初余额应该得到更新,以下是我想要的示例输出:;今天打开余额=昨天关闭余额

date       opening_balance   closing_balance  accountformatid daybooktype
18-02-2013  12000               15000           1               240
19-02-2013  15000               14000           1               240
20-02-2013  14000               13000           1               240
21-02-2013  13000               10000           1               240
22-02-2013  10000               5000            1               240
23-02-2013  50000               1500            1               240
这个acheived plz怎么能帮我呢

试试这个:

DECLARE @t TABLE (date DATETIME,      opening_balance  INT, closing_balance  INT,accountformatid INT,daybooktype INT)

INSERT @t 
SELECT CONVERT(DATE, a, 105), b,c,d,e
FROM (VALUES
('18-02-2013',12000  ,15000 ,1,240),
('19-02-2013',15000  ,14000 ,1,240),
('20-02-2013',14000  ,13000 ,1,240),
('21-02-2013',13000  ,10000 ,1,240),
('22-02-2013',10000  ,5000  ,1,240),
('23-02-2013',50000  ,1500  ,1,240)
) tbl(a,b,c,d,e)

SELECT  t1.*
        , t2.*
FROM    @t t1
LEFT JOIN   
        @t t2 ON t1.date = DATEADD(DAY, 1, t2.date)
AND     t1.opening_balance = t2.closing_balance
WHERE   t2.closing_balance IS NULL
-- this prevents first record to be falsely reported
AND     t1.date <> (SELECT MIN(date) FROM @t)

这列出了两条后续记录中的第二条,这些记录与日期和余额不符。

不清楚。澄清你的问题。