running average in mysql

后端 未结 4 1274
刺人心
刺人心 2021-01-25 06:15

I have the table like below

id   timestamp  speed
1    11:00:01   100
2    11:05:01   110
3    11:10:01   90
4    11:15 :01  80

I need to calcu

4条回答
  •  深忆病人
    2021-01-25 07:16

    What about a simple concurrent solution?

    SET @summ=0; SET @counter=0;SELECT *,(@counter := @counter +1) as cnt, (@summ := @summ+speed) as spd, (@summ/@counter) AS avg FROM tbl;
    

提交回复
热议问题