获取mysql中每天一列的平均值

时间:2017-06-09 06:49:50

标签: mysql average

我尝试按日列获取表格的平均值,例如

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

之前谢谢

1 个答案:

答案 0 :(得分:1)

使用AVG()

SELECT `day` AS `Day`,
       AVG(`value`) AS `Average`
FROM `table`
WHERE `day` <= 5
GROUP BY `day`
ORDER BY `day` ASC;