【问题标题】:Update with last known location?更新最后一个已知位置?
【发布时间】:2014-02-22 21:10:36
【问题描述】:

我有一个包含大约 75,000 个位置的大型数据表 一天中的每分钟,持续 24 小时。列是:

ppid(个人 ID) point_time(时间戳) the_geom(几何点)

我的问题是该位置的一些(很多)信息 (the_geom) 列丢失。此列需要与最后更新 该人的已知位置。我在概念上正在努力解决如何做到这一点。我认为桌上有某种自加入。但是如何获得正确的数据 更新?

我制作了一个演示问题的 SQL 小提琴:

http://sqlfiddle.com/#!15/77157/1

谢谢

詹姆斯

【问题讨论】:

    标签: sql postgresql timestamp geometry postgis


    【解决方案1】:

    我不确定这将如何在更大的数据集上执行,但这是一个使用两个嵌套子查询的单一查询解决方案:

    SELECT
      data.ppid,
      data.point_time,
      CASE
        WHEN data.the_geom IS NULL
        THEN (
          --Get all locations with an earlier time stamp for that ppid
          SELECT geom.the_geom
          FROM test_data geom
          WHERE data.ppid = geom.ppid
          AND geom.point_time < data.point_time
          AND geom.the_geom IS NOT NULL
          AND NOT EXISTS (
            -- Cull all but the most recent one
            SELECT *
            FROM test_data cull
            WHERE cull.ppid = geom.ppid
            AND geom.the_geom IS NOT NULL
            AND cull.point_time < data.point_time
            AND cull.point_time > geom.point_time
            AND cull.the_geom IS NOT NULL
            )
        )
      ELSE data.the_geom
      end
    FROM test_data data
    

    【讨论】:

    • 天哪。做得好。太精彩了。非常感谢。我现在将使用我的大型数据集运行它,看看效果如何。
    猜你喜欢
    • 2011-08-22
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2019-12-08
    相关资源
    最近更新 更多