我目前正在尝试为工作创建数据库,我以前从未使用过Access。到目前为止,我已经设法创建了一个数据输入表单,该表单可以输入_be表。
我现在想做的是能够查询3种格式(YTD,MTD,WTD)的记录总数,然后按“飞机模型”分组,这是我分别完成的。问题是当我尝试将数据放在报表上时,我必须创建子报表以包括所有3个查询。
有没有一种方法可以将所有这些合并到一个查询中或合并我所拥有的查询而不损害数据?到目前为止,当我尝试使用“联合”或“联接”时,数据输入不正确。我要查询的字段对于每个查询都是相同的,只是日期是不同的条件。
YTD SQL
SELECT [BlueStreak Tracking1].[Airplane Model], Count(*) AS [This Year]
FROM [BlueStreak Tracking1]
WHERE ((([BlueStreak Tracking1].[Issue Date]) Between DateSerial(Year(Date()),1,1) And DateSerial(Year(Date()),12,31)))
GROUP BY [BlueStreak Tracking1].[Airplane Model]
ORDER BY [BlueStreak Tracking1].[Airplane Model];
MTD SQL
SELECT [BlueStreak Tracking1].[Airplane Model], Count(*) AS [This Month]
FROM [BlueStreak Tracking1]
WHERE (((Year([Issue Date]))=Year(Date())) AND ((Month([Issue Date]))=Month(Date())))
GROUP BY [BlueStreak Tracking1].[Airplane Model]
ORDER BY [BlueStreak Tracking1].[Airplane Model];
WTD SQL
SELECT [BlueStreak Tracking1].[Airplane Model], Count(*) AS [This Week]
FROM [BlueStreak Tracking1]
WHERE ((([BlueStreak Tracking1].[Issue Date]) Between DateAdd("d",-((Weekday(Date())-1)),Date()) And Date()))
GROUP BY [BlueStreak Tracking1].[Airplane Model]
ORDER BY [BlueStreak Tracking1].[Airplane Model];
答案 0 :(得分:0)
您应该能够在“全部联合”中做到这一点。看看是否可行:
SELECT [BlueStreak Tracking1].[Airplane Model], 'This Year' as [TimeFrame], Count(*)
FROM [BlueStreak Tracking1]
WHERE ((([BlueStreak Tracking1].[Issue Date]) Between DateSerial(Year(Date()),1,1)
And DateSerial(Year(Date()),12,31)))
GROUP BY [BlueStreak Tracking1].[Airplane Model]
UNION ALL
SELECT [BlueStreak Tracking1].[Airplane Model], 'This Month', Count(*)
FROM [BlueStreak Tracking1]
WHERE (((Year([Issue Date]))=Year(Date())) AND ((Month([Issue Date]))=Month(Date())))
GROUP BY [BlueStreak Tracking1].[Airplane Model]
UNION ALL
SELECT [BlueStreak Tracking1].[Airplane Model], 'This Week', Count(*)
FROM [BlueStreak Tracking1]
WHERE ((([BlueStreak Tracking1].[Issue Date]) Between DateAdd("d",-
((Weekday(Date())-1)),Date()) And Date()))
GROUP BY [BlueStreak Tracking1].[Airplane Model]
ORDER BY [BlueStreak Tracking1].[Airplane Model];