select id, sales_vol, (select avg(sales_vol) as mavg 
                         from tbl b
                        where b.id between a.id - 3 and a.id)
  from tbl a;

---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org


> -----Original Message-----
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of ???
> Sent: Saturday, 11 August, 2012 22:46
> To: sqlite-users@sqlite.org
> Subject: [sqlite] how to update the Moving average value
> 
> I hace many record of product database,and wanna count the moving average
> value of sales_vol of last 3 days(id) of value, how to write sql command?
> 
> id  Sales_vol      mov_avg
> 1     1
> 2     2
> 3     3           =(1+2+3)/3
> 4     5           =(2+3+5)/3
> 5     4           =(3+5+4)/3
> 6     2           =(5+4+2)/3
> 7............
> .......
> 
> 
> 
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to