我想在Microsoft Access 2016中执行查询,显示范围(最大 - 最小)与每日平均值。
我已经完成了一个查询,显示“16-Jun-16”和“17-Jun-16”之间所有记录的结果:
SELECT [Date Time], [Operation Grade-Load], [MFR g/10min]
FROM [In process analysis result]
WHERE ([Date Time] Between Date()-360 And Date()-358)
AND ([Operation Grade-Load] Like "MH*");
但是,我对如何继续修改我的查询以显示每天的“范围”和“平均值”一无所知。我想我应该使用Avg(),Max() - Min()函数。任何人都可以指导我吗?
编辑: 每天根据[前一天02:00:00]和[今天02:00:00]计算。 例如:
甚至可以根据这个逻辑计算日期吗?
感谢任何帮助。 谢谢。
编辑1: 我更新了我的SQL查询:
SELECT [Date Time], [Range], [Average]
FROM [In process analysis result], (SELECT Max([MFR g/10min])-Min([MFR g/10min]) AS [Range], Avg([MFR g/10min]) AS Average
FROM [In process analysis result]
WHERE ((([In process analysis result].[Date Time]) Between Date()-360 And Date()-358) AND (([In process analysis result].[Operation Grade-Load]) Like "MH*"))
) AS [%$##@_Alias]
WHERE ((([In process analysis result].[Date Time]) Between Date()-360 And Date()-358) AND (([In process analysis result].[Operation Grade-Load]) Like "MH*"))
ORDER BY [In process analysis result].[Date Time];
结果证明它足够接近我想要的......但还没有,因为它不是基于每天计算的。
编辑2: 这是预期的结果:
编辑3: 在@USeptim之后,这是创建的查询的结果。但是,它会使用[Range]和[PromedioDeMFR g / 10min]创建另外两列。
答案 0 :(得分:0)
你可以这样做:
SELECT [In process analysis result].[Date Time], [In process analysis
result].[MFR g/10min], QueryAux.Range, QueryAux.[PromedioDeMFR g/10min]
FROM [In process analysis result] INNER JOIN
(SELECT Max([MFR g/10min])-Min([MFR g/10min]) AS Range, Avg([In process
analysis result].[MFR g/10min]) AS [PromedioDeMFR g/10min], [In process
analysis result].[Date Time], [In process analysis result].[Operation Grade-
Load]
FROM [In process analysis result]
GROUP BY [In process analysis result].[Date Time], [In process analysis
result].[Operation Grade-Load]) QueryAux
ON ([In process analysis result].[Operation Grade-Load] = QueryAux.
[Operation Grade-Load]) AND ([In process analysis result].[Date Time] =
QueryAux.[Date Time])
WHERE ((([In process analysis result].[Date Time]) Between Date()-360 And
Date()-358) AND (([In process analysis result].[Operation Grade-Load]) Like
"MH*"))
ORDER BY [In process analysis result].[Date Time];
您可以使用我调用的子查询创建一个查询" query aux"并直接引用它。