需要一些帮助计算Microsoft Access Query

时间:2017-08-25 17:06:38

标签: ms-access

我想根据事务日期(TrxDate)和成员名称(MemberName)计算字段BalanceCalculationA的累计数据。查询目前的图像可以在下面的附件中看到。我已经尝试编辑SQL语句来计算累积数据,但无济于事。我很难过。这是我的代码:

SELECT MoneyJournal.[GroupNumber], MoneyJournal.[MemberName], MoneyJournal.[TrxDate], MoneyJournal.[Deposits], MoneyJournal.[Withdrawals], [Deposits]-[Withdrawals] AS BalanceCalculationA, 

(SELECT sum(abc.[BalanceCalculationA])
FROM [MoneyJournal Query] as abc
WHERE abc.[MemberName]=MoneyJournal.[MemberName] 
AND abc.[TrxDate]<=MoneyJournal.[TrxDate]) AS [BalanceCalculationB]

FROM MoneyJournal;

如果有人可以为我提供可以计算累积数据而无需编辑SQL语句的解决方法,那么绝对欢迎您这样做。任何帮助深表感谢。 Image Attachment click here

1 个答案:

答案 0 :(得分:0)

可能需要从同一个表中提取数据,而不是另一个查询:

SELECT 
    MoneyJournal.[GroupNumber], 
    MoneyJournal.[MemberName], 
    MoneyJournal.[TrxDate], 
    MoneyJournal.[Deposits], 
    MoneyJournal.[Withdrawals], 
    [Deposits]-[Withdrawals] AS BalanceCalculationA,    
        (SELECT SUM(abc.[Deposits]-abc.[Withdrawals])
        FROM MoneyJournal AS abc
        WHERE abc.[MemberName]=MoneyJournal.[MemberName] 
        AND abc.[TrxDate]<=MoneyJournal.[TrxDate]) AS 
    [BalanceCalculationB]
FROM 
    MoneyJournal;