Access get value from previous record

后端 未结 4 1490
你的背包
你的背包 2021-01-25 20:46

I have an Access query with the following

GL_A.Account, 
GL_P.FiscalYear, 
GL_P.FiscalPeriod, 
GL_P.BeginningBalance, 
GL_P.DebitAmount, 
GL_P.CreditAmount, 
[B         


        
4条回答
  •  [愿得一人]
    2021-01-25 21:05

    This SQL does the job and returns the table below (with my test data):

    SELECT    T1.Account
            , T1.FiscalYear
            , T1.FiscalPeriod
            , T1.ActualBeginngBal
            , (
               SELECT TOP 1 T2.EndingBalance
               FROM   Table1 T2
               WHERE CLNG(T2.FiscalYear & Format(T2.FiscalPeriod,"00")) <
                     CLNG(T1.FiscalYear & Format(T1.FiscalPeriod,"00")) AND
                     T2.Account = T1.Account
               ORDER BY CLNG(T2.FiscalYear & Format(T2.FiscalPeriod,"00")) DESC
               ) AS BeginningBalance
            , T1.EndingBalance
    FROM    Table1 T1
    

提交回复
热议问题