这个问题与此接近:
Find the period of over speed?
这是我的桌子:
Longtitude Latitude Velocity Time
102 401 40 2010-06-01 10:22:34.000
103 403 50 2010-06-01 10:40:00.000
104 405 0 2010-06-01 11:00:03.000
104 405 0 2010-06-01 11:10:05.000
105 406 35 2010-06-01 11:15:30.000
106 403 60 2010-06-01 11:20:00.000
108 404 70 2010-06-01 11:30:05.000
109 405 0 2010-06-01 11:35:00.000
109 405 0 2010-06-01 11:40:00.000
105 407 40 2010-06-01 11:50:00.000
104 406 30 2010-06-01 12:00:00.000
101 409 50 2010-06-01 12:05:30.000
104 405 0 2010-06-01 11:05:30.000
我想总结一下车辆停止的时间(速度=0),包括:从“何时”到“何时”停止的时间(以分钟为单位)、停止的次数以及停止的时间。
我写这个查询是为了完成它:
select longtitude, latitude, MIN(time), MAX(time), DATEDIFF(minute, MIN(Time), MAX(time))
as Timespan from table_1 where velocity = 0 group by longtitude,latitude
select DATEDIFF(minute, MIN(Time), MAX(time)) as minute into #temp3
from table_1 where velocity = 0 group by longtitude,latitude
select COUNT(*) as [number]from #temp
select SUM(minute) as [totaltime] from #temp3
drop table #temp
此查询返回:
longtitude latitude (No column name) (No column name) Timespan
104 405 2010-06-01 11:00:03.000 2010-06-01 11:10:05.000 10
109 405 2010-06-01 11:35:00.000 2010-06-01 11:40:00.000 5
number
2
totaltime
15
你看,它很好用,但我真的不喜欢临时桌。是否仍然可以在不使用临时表的情况下查询此信息?
谢谢您。