mysql interpolate data

纵然是瞬间 提交于 2019-12-25 00:09:45

问题


Is there an 'easy way' to grab two rows of data from a table, and add rows with values 'in-between'?

I want to grab a latitude, a longitude and a timestamp from each row. Compare the timestamp to the one from the previous row, and interpolate new rows if the timestamp is bigger than my minimum...grab two rows 1 minute apart and add rows for every 10 seconds...

Is using a stored procedure the best way to go about this? Easiest?

Currently using mySql and PHP...


回答1:


I would just grab the data and do the math in PHP. SQL isn't all that versatile, and you'd be saving yourself a headache.

EDIT: Actually, just for the fun of it, you could make the math easier by left-joining to a calendar table.

First you need a table ints with the values 0-9. Then you can do something like:

SELECT cal.t, lat, lng FROM (
    SELECT {start_time} + INTERVAL (t.i*1000 + u.i*100 + v.i*10) SECOND as t
    FROM ints as t
    JOIN ints as u
    JOIN ints as v
    WHERE t <= {end_time}
) LEFT JOIN locations ON (cal.t = locations.stamp)

This would return a table with NULL values for lat and lng where there isn't an entry on the 10 second mark, so you could iterate through and do the math for just those. Keep in mind, this only works if you all the datapoints you do have (other than the start and end) land right on a 10-second mark.



来源:https://stackoverflow.com/questions/5758800/mysql-interpolate-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!