On 12-08-2012 20:49, Klaas V wrote:
Keith Metcalf wrote:


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............

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;

- 3 should be - 2. You're working with the last 4 days and might get an error 
if id=3
:P


Why 'might' there be an error?

It perfectly valid to write:
 ..... where b.id between 0 and 3)
or
 ..... where b.id between -1 and 2)




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

Reply via email to