我尝试按日列获取表格的平均值,例如
table1
id | day | value |
F01 | 01 | 3 |
F02 | 02 | 2 |
F03 | 03 | 1 |
F04 | 04 | 2 |
F05 | 05 | 2 |
. | . | . |
. | . | . |
F30 | 30 | 4 |
F31 | 31 | 2 |
从上表中我想从value
列获得5天的平均值,因此在上面的示例中,我将获得值2
。
答案 0 :(得分:1)
使用AVG()
:
SELECT `day` AS `Day`,
AVG(`value`) AS `Average`
FROM `table`
WHERE `day` <= 5
GROUP BY `day`
ORDER BY `day` ASC;