MS Access 2016 查询范围与每天的平均值
Posted
技术标签:
【中文标题】MS Access 2016 查询范围与每天的平均值【英文标题】:MS Access 2016 Query Range vs Average per Day 【发布时间】:2017-06-10 17:59:37 【问题描述】:我想在 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] 之间计算的。 示例:
16-Jun-16 = “16-Jun-16 02:00:00”和“17-Jun-16”之间的行记录 02:00:00" 17-Jun-16 = “17-Jun-16 02:00:00”和 "18-Jun-16 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] 创建另外两列。
【问题讨论】:
向我们展示您预期结果的示例 @dbajtr 请参阅我原帖中的编辑 2。 【参考方案1】:你可以这样做:
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];
您可以使用我称为“查询辅助”的子查询创建一个查询并直接引用它。
【讨论】:
谢谢先生。我运行了查询,它显示了我在原始帖子的编辑 3 中发布的内容。它创建了两个额外的列,[Range] 和 [PromedioDeMFR g/10min]。我应该如何处理这两列? [PromedioDeMFR g/10min] 应称为 [Average],另一方面,[Range] 是查询中显示的列:SELECT Max([MFR g/10min])-Min( [MFR g/10min]) AS [范围], Avg([MFR g/10min]) AS 平均以上是关于MS Access 2016 查询范围与每天的平均值的主要内容,如果未能解决你的问题,请参考以下文章