访问中的联合查询

时间:2016-08-02 10:30:59

标签: sql ms-access union-all

这是我的代码

Transform IIf(IsNull(Count(monthTable.monthNumber)), 
            "0", 
            IIf(Count(monthTable.monthNumber) = 0, 
                "Yes", 
                IIf(Count(monthTable.monthNumber) < 1, 
                    "error", 
                    first(Resource_Allocation.[Chargebility]))))
SELECT Resource_Allocation.[Employee ID],
       Resource_Allocation.[Project Name],
       first(Resource_Allocation.[Project Tower]) AS Tower,
       first(Resource_Allocation.[Enterprise ID]) AS [Enterprise Id],
       first(Resource_Allocation.[Role Title]) AS [Role Title],
       first(Resource_Allocation.[Chargebility]) AS chargeblity,
       first(Resource_Allocation.[Actual Roll-On Date]) AS [Role On Date],
       first(Resource_Allocation.[Estimated Roll-Off Date]) As [Role Off Date]
FROM Resource_Allocation,
     monthTable
WHERE monthTable.monthNumber BETWEEN
    iif(Resource_Allocation.[Actual Roll-On Date] > #1-1-2016#,
        iif(Resource_Allocation.[Actual Roll-On Date] < #31-12-2016#,
            month([Resource_Allocation]![Actual Roll-On Date]),
            iif(Resource_Allocation.[Actual Roll-On Date] < #1-1-2016# ,0,1)),
        iif(Resource_Allocation.[Estimated Roll-Off Date] < #1-1-2016#,0,0))
AND iif(Resource_Allocation.[Estimated Roll-Off Date] > #1-1-2016#,
        iif(Resource_Allocation.[Estimated Roll-Off Date] < #31-12-2016#,
            month([Resource_Allocation]![Estimated Roll-Off Date]),
            iif(Resource_Allocation.[Estimated Roll-Off Date] < #31-12-2016#,0,12)),
        iif(Resource_Allocation.[Estimated Roll-Off Date] < #1-1-2016#,0,0))
GROUP BY Resource_Allocation.[Project Name],
         Resource_Allocation.[Employee ID] 
PIVOT monthTable.monthName IN(January,February,March,April,May,June,July,August,September,October,November,December);

我想要在最后一行的列中显示的月份中的所有数据的总和。我尝试使用union all,但它没有工作

请帮帮我。

提前致谢

0 个答案:

没有答案