donglian6625 2011-04-22 18:42
浏览 42
已采纳

mysql插入数据

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条回答 默认 最新

  • dousuowu4610 2011-04-22 19:36
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探