我想计算表格中所选列的平均值。 例如,我有一张表,其中一年中每周有52列。现在我想计算当前一周到第42周的平均值。范围将从表格中给出。
请帮助解决这个问题。
答案 0 :(得分:0)
古斯塔夫是对的,你没有正确设置你的表,但如果你将你的52周联合起来,这仍然是可能的,如下面的例子,它来自一个名为data的表,并且每周都有一个ID列和一列:
SELECT ID, count(ID) as count, Sum(stat) AS Total, sum(stat)/count(id) as average
FROM (
SELECT Data.ID, Data.[Week 1] as stat
FROM Data
UNION ALL SELECT Data.ID, Data.[Week 2] as stat
FROM Data
UNION ALL SELECT Data.ID, Data.[Week 3] as stat
FROM Data
\\...add further unions here as required
) GROUP BY ID;