MS Access平均基于其他列数据的值

问题描述 投票:0回答:2

所以我的数据看起来像这样:

Smpl_id Plate_id CT_Value
  1        1       27
  1        1       32
  2        1       56
  2        1       49
  1        2       40
  1        2       36
  2        2       58
  2        2       64

我想设计一个查询,该查询返回板中每个样本的CT_Value平均值,因此它看起来像这样:

Smpl_id Plate_id Avg_CT
  1         1     29.5
  2         1     52.5
  1         2     38
  2         2     61

我尝试过

Avg_CT: DAvg("[CT_Value]","[qPCR_sample_data]","[Plate_id] = '" & [Plate_id] & "'" And "[Smpl_is] = '" & [Smpl_id] & "'")

但是那只会导致:

Smpl_id Plate_id CT_Value
  1        1      45.25
  1        1      45.25
  2        1      45.25
  2        1      45.25
  1        2      45.25
  1        2      45.25
  2        2      45.25
  2        2      45.25

我不能只列出板号或样品的ID号,因为这实际上是一长串,而且还在不断增长。我还需要在以后的计算中使用这些平均值(我已经弄清楚该怎么做)。

而且,我刚刚开始使用MS Access(设计一个全新的数据库),所以我有点理解SQL,但对它的实际经验很少。

谢谢!

ms-access average
2个回答
0
投票

您应该能够使用简单的聚合,例如:

select t.smpl_id, t.plate_id, avg(t.ct_value) as avg_ct
from qpcr_sample_data t
group by t.smpl_id, t.plate_id

0
投票

您将需要使用分组查询。

  • 创建一个新查询,并添加表(在我的示例中,我将其称为tblSample)。
  • 将三个字段Smpl_id,Plate_id和CT_Value添加到查询网格。
  • 在查询设计菜单上,单击标记为“总计”的按钮。
  • 这将在查询网格中引入一个名为“总计”的新行,所有三个字段均将其设置为“分组依据”。
  • 只需将CT_Value的“分组依据”更改为“平均”,然后运行查询以获取您想要的结果:

enter image description here

问候,

© www.soinside.com 2019 - 2024. All rights reserved.