我是新手,我正在尝试根据表格中的信息创建报告。以下是表格中当前数据的示例...
id Date Name Location Model Count
1 06/10/2012 William Basement Desktop 22
2 06/10/2012 Doug Top Floor Desktop 15
3 06/10/2012 Jane Top Floor Laptop 12
4 06/11/2012 William Basement Desktop 29
5 06/11/2012 Doug Top Floor Desktop 35
6 06/12/2012 William Basement Desktop 31
7 06/12/2012 Doug Top Floor Desktop 41
8 06/12/2012 Jane Top Floor Laptop 24
现在我要做的是创建一个报告,该报告将按月分组并累计计数,计算最后一个计数并从记录的月份的第一天减去第一个计数。因此,我的报告应该看起来像这样,遗漏ID,因为这不是报告的必要数据。
Date Name Location Model Count
June 2012 William Basement Desktop 9
June 2012 Doug Top Floor Desktop 26
June 2012 Jane Top Floor Laptop 12
如果有人有任何想法我怎么能做到这一点,记住我很新,访问,这将是伟大的!
答案 0 :(得分:0)
您可以先创建一个查询,然后根据该查询创建报告。包含一个可以设置为MaxOfCount和MinOfCount之间差异的控件。
SELECT DISTINCT Format([Date],"yyyy mm") AS Sort,
Format([Date],"mmm yyyy") AS [Month],
a.Name, a.Location, a.Model,
(SELECT TOP 1 [Count]
FROM Report b
WHERE a.Name=b.Name AND a.Location=b.Location AND a.Model=b.Model
ORDER BY [Date] DESC, Id) As MaxOfCount,
(SELECT TOP 1 [Count]
FROM Report b
WHERE a.Name=b.Name AND a.Location=b.Location AND a.Model=b.Model
ORDER BY [Date], Id) AS MinOfCount
FROM Report a