且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MS Access 2010在查询中的运行总计

更新时间:2023-09-24 23:17:28

您可以通过相关子查询获得所需的内容.

You can get what you want with a correlated subquery.

SELECT
    a1.agentID,
    a1.incurrredDate,
    a1.points,
    a1.OneFallOff,
    a1.TwoFallOff
    (
        SELECT Sum(a2.TwoFallOff)
        FROM attendanceView AS a2
        WHERE
                a2.agentID = a1.agentID
            AND a2.incurrredDate <= a1.incurrredDate
    ) AS total
FROM attendanceView AS a1;

您也可以使用DSum来做到这一点,但是随后您需要在DSum WhereCondition 选项中使用带有agentIDincurrredDate的定界符.与子查询方法相比,这似乎需要更多的精力,而且我发现它更容易出错.

You could also do it with DSum, but then you need to use delimiters with agentID and incurrredDate in the DSum WhereCondition option. It seems like more effort, and I found it more error-prone, than the subquery approach.

SELECT
    a.agentID,
    a.incurrredDate,
    a.points,
    a.OneFallOff,
    a.TwoFallOff,
    DSum
        (
            "TwoFallOff", "attendanceView",
            "agentID = '" & a.agentID & "' " &
            "AND incurrredDate <= " & 
            Format(a.incurrredDate, "\#yyyy-m-d\#")
        ) AS total
FROM attendanceView AS a;

两个查询都使用Access 2007中的示例数据返回请求的结果.

Both queries return your requested results using your sample data in Access 2007.