如何根据其他列的条件输出一列的平均值?例如,这就是我所做的:
SELECT
AVG(TestScores WHERE ID = 1 AND Date_On BETWEEN '2017-04-08' AND '2017-04-12' AND Code = '87A')
FROM
Table_Name
我希望的目标是在TestScores
ID
的{{1}}以及日期在指定的时间间隔之间获得row = 1
列的平均值。这可能吗?
答案 0 :(得分:1)
如果您使用的是Sql Server,那么下面就是您要查找的内容(我认为):
SELECT
AVG(TestScores)
FROM
Table_Name
WHERE ID = 1
AND Date_On BETWEEN '2017-04-08' AND '2017-04-12'
AND Code = '87A'
编辑,根据下面的评论:
SELECT
ID,
AVG(TestScores)
FROM
Table_Name
WHERE
Date_On BETWEEN '2017-04-08' AND '2017-04-12'
AND Code = '87A'
GROUP BY ID
答案 1 :(得分:0)
这是查询: -
SELECT AVG(TestScores)
FROM Table_Name
WHERE ID = 1 AND
Date_On BETWEEN '2017-04-08' AND '2017-04-12' AND Code = '87A'