(列)GatherDate (列)speed
2013-10-19 08:00:41 0.0
2013-10-19 08:10:30 0.0
2013-10-19 08:20:30 0.0
2013-10-19 08:30:30 NULL
2013-10-19 08:50:30 0.0
2013-10-19 09:00:30 0.0
2013-10-19 09:07:30 0.0
2013-10-19 09:08:30 11.0
2013-10-19 09:09:30 22.0
得出一个指定时间间隔(如10分钟,大于十分钟则归到下一时间段)且速度一直为0 表
(列)起始时间 (列)终止时间 (列)停滞时间
2013-10-19 08:00:41 2013-10-19 08:20:30 19
2013-10-19 08:50:30 2013-10-19 09:07:30 17sql语句数据
解决方案 »
- 动态管理视图和函数的刷新问题
- |zyciis| 如何在PowerDesign中设置在界面上显示 Name Code Common
- 急:sql 2005 report services 发布不了
- 如何提高SQL运行效率(二): 如何以最快的速度判断一个SQL选择查询语句是否正确?
- 有没有象EXCEL一样方便直接编辑SQL数据的软件?
- 因什么报“在函数内不正确f 使用了execute”的错误.附件原函数
- 《数据库系统概论》的中文电子版哪有下载?
- 数据库恢复后,MDF无法附加,求教.
- 哪里有vfp7下载?
- DTS的文本到文本能否加限制只取满足条件的行?
- 层级数据如何插入
- 触发器可以这样写吗 向一个表添加一条信息 另外一个表同时也添加刚刚添加的那条信息
create table hq
(GatherDate varchar(30),speed decimal(5,1))insert into hq
select '2013-10-19 08:00:41', 0.0 union all
select '2013-10-19 08:10:30', 0.0 union all
select '2013-10-19 08:20:30', 0.0 union all
select '2013-10-19 08:30:30', NULL union all
select '2013-10-19 08:50:30', 0.0 union all
select '2013-10-19 09:00:30', 0.0 union all
select '2013-10-19 09:07:30', 0.0 union all
select '2013-10-19 09:08:30', 11.0 union all
select '2013-10-19 09:09:30', 22.0
with t as
(select GatherDate,
case when speed=0.0 then 1 else 0 end 'x',
row_number() over(order by getdate()) 'rn'
from hq)
select min(GatherDate) '起始时间',
max(GatherDate) '终止时间',
datediff(mi,min(GatherDate),max(GatherDate)) '停滞时间'
from
(select a.GatherDate,
a.rn-row_number() over(order by a.rn) 'rn'
from t a where a.x=1) t
group by rn/*
起始时间 终止时间 停滞时间
------------------------------ ------------------------------ -----------
2013-10-19 08:00:41 2013-10-19 08:20:30 20
2013-10-19 08:50:30 2013-10-19 09:07:30 17(2 row(s) affected)
*/