drop table if exists log1;
set @a:=0;
create table log1
select @a:=@a+1 as row_id,v1.*
from vending_log v1 order by sold_ts;
alter table log1 add primary key(row_id);
select avg(unix_timestamp(v1.sold_ts)-unix_timestamp(v2.sold_ts)) as avg_diff
from log1 v1, log1 v2
where v2.row_id=v1.row_id - 1;