"当月"和"每月累计支出"同一查询中的数据

时间:2015-02-13 03:53:08

标签: sql ms-access

在MS ACCESS中工作,我试图用"当前月份和#34;来查询Table_projFunding_ActionQuery.MonthlyExpenditure字段。 (Table_ProjFunding_ActionQuery.MonthlyExpenditure)和"累计每月支出" (Sum(Table_ProjFunding_ActionQuery.MonthlyExpenditure)AS CumExp)数据在同一个查询中没有成功。请参阅以下SQL代码。

这里我尝试使用标量方法,但它只将数据过滤到子查询中的第一个日期范围。代码底部的HAVING语句与结果无关。

提前感谢您的意见。


SELECT 
    Table_ProjFunding_ActionQuery.SLIN_Number, 
    Table_ProjFunding_ActionQuery.ACRN, 
    Table_ProjFunding_ActionQuery.FundingReceived, 
    Sum(Table_ProjFunding_ActionQuery.MonthlyExpenditure) AS CumExp, 
    Table_ProjFunding_ActionQuery.MonthlyHoursCharged, 
    Table_ProjFunding_ActionQuery.ProjectName, 
    Table_ProjFunding_ActionQuery.FwdFundingPlan, 
    Table_ProjFunding_ActionQuery.FY15FundingPlan, 
    Sum(Table_ProjFunding_ActionQuery.MonthlyExpenditure) AS SumOfMonthlyExpenditure1, 
    Table_ProjFunding_ActionQuery.MonthlyExpenditure
FROM 
    Table_ProjFunding_ActionQuery
WHERE 
    (
        ((Table_ProjFunding_ActionQuery.MonthlyExpenditure) In 
            (SELECT 
                Table_ProjFunding_ActionQuery.MonthlyExpenditure
            FROM 
                Table_ProjFunding_ActionQuery
            WHERE 
                Table_ProjFunding_ActionQuery.MonthEndDate BETWEEN #10/01/2014# AND #11/01/2014#
            )
        )
    )
GROUP BY 
    Table_ProjFunding_ActionQuery.SLIN_Number, 
    Table_ProjFunding_ActionQuery.ACRN, 
    Table_ProjFunding_ActionQuery.FundingReceived, 
    Table_ProjFunding_ActionQuery.MonthlyHoursCharged, 
    Table_ProjFunding_ActionQuery.ProjectName, 
    Table_ProjFunding_ActionQuery.FwdFundingPlan, 
    Table_ProjFunding_ActionQuery.FY15FundingPlan, 
    Table_ProjFunding_ActionQuery.MonthlyExpenditure
HAVING 
    (
        ((Sum(Table_ProjFunding_ActionQuery.MonthlyExpenditure)) In 
            (SELECT 
                Table_ProjFunding_ActionQuery.MonthlyExpenditure
            FROM 
                Table_ProjFunding_ActionQuery
            WHERE 
                Table_ProjFunding_ActionQuery.MonthEndDate <= Now()
            )
        )
    );

0 个答案:

没有答案