Comparing previous/next record to calculate an average speed
Getting the previous row is very easy in Postgres:

select id, 
       speed, 
       "time", 
       extract(epoch from lag("time") over (order by "time") - "time") as diff_seconds,
from the_table
order by "time";


The whole calculation would be:

select extract(epoch from max("time") - min("time")) as total_seconds, 
       sum(diff_distance) / extract(epoch from max("time") - min("time")) as avg_speed
from (
  select id, 
         speed, 
         "time", 
         extract(epoch from lag("time") over (order by "time") - "time") as diff_seconds,
         speed * extract(epoch from lag("time") over (order by "time") - "time") as diff_distance
  from the_table
  order by "time"
) t;


Subtracting a timestamp from a timestamp yields an interval. Using extract(epoch ...) converts the interval to the total number of seconds in that interval.

The column diff_distance isn't really necessary, I just added that for debugging purposes.

This however is currently not possible in MySQL.