mysql - 确定在特定位置停工

mysql - determine stoppages at a particular location

我有一个 mysql table 如下(5 列):

id |Vehicle_no |Time | latitude |Longitude

1 |Abc123 |2015-09-15 20:15:51 | 26.211718 | 86.877197

2 |Abc123 |2015-09-15 20:16:51 | 26.211718 | 86.877197

3 |Abc123 |2015-09-15 20:17:51 | 26.211718 | 86.877197

4 |Abc123 |2015-09-15 20:18:51 | 26.211718 | 86.877197

5 |Abc123 |2015-09-15 20:19:51 | 26.211718 | 86.877197

6 |Abc123 |2015-09-15 20:20:51 | 26.212718 | 86.878197

7 |Abc123 |2015-09-15 20:21:51 | 26.212728 | 86.878200

8 |Abc123 |2015-09-15 20:22:51 | 26.212738 | 86.877201

上述值是我每分钟从 GPS 接收器获取的。如果纬度和经度在特定日期保持不变,例如超过 5 分钟,我必须表明车辆在该特定日期停在该位置(纬度和经度)。在 table 中获取 id。没有 6、7 有不同的纬度。长表示车辆正在移动。 纬度的值。和long可能会重复,因为我每天都穿过同一条路线(相同的纬度和经度。)但时间和日期可能不同。

select id, 1 as is_stationary from positions p
where not exists (select 0 from positions pp
    where p.time > pp.time
    and datediff(p.time, pp.time) <= 5/(60*24)
     and p.latitude <> pp.latitude
     and p.longitude <> pp.longitude)

我不知道你想对结果做什么——将其写入新列或其他内容——所以考虑将第一行 "from" 之前的内容作为虚拟占位符。