某列在两条相邻的记录之间的差值
2008-05-23 23:49
323 查看
求某列在两条相邻的记录之间的差值,可扩展应用
求出符合条件的记录,以下语句是以时间作为差值条件
1: 表变量的方法
declare @a table (tid int identity(1,1),id int,t1 datetime)
insert into @a(id,t1) select id,updatetime from book order by id
--select * from @a
select aaa.id,aaa.t1,bbb.id2,bbb.t2 from @a as aaa inner join(select tid as tid2,id as id2,t1 as t2 from @a ) as bbb on aaa.tid=bbb.tid2-1 where datediff(mi,aaa.t1,bbb.t2)>20
2:直接查询法,效率高
Select id,updatetime
from book a
where datediff(mi,updatetime,(select top 1 updatetime from book where id > a.id order by id) ) > 20
order by id
求出符合条件的记录,以下语句是以时间作为差值条件
1: 表变量的方法
declare @a table (tid int identity(1,1),id int,t1 datetime)
insert into @a(id,t1) select id,updatetime from book order by id
--select * from @a
select aaa.id,aaa.t1,bbb.id2,bbb.t2 from @a as aaa inner join(select tid as tid2,id as id2,t1 as t2 from @a ) as bbb on aaa.tid=bbb.tid2-1 where datediff(mi,aaa.t1,bbb.t2)>20
2:直接查询法,效率高
Select id,updatetime
from book a
where datediff(mi,updatetime,(select top 1 updatetime from book where id > a.id order by id) ) > 20
order by id
相关文章推荐
- 忆龙2009:自动计算相邻两条记录指定字段的差值
- sql相邻两条记录差值计算 初稿
- 两个相邻时间之间的差值计算
- 最大间隙问题。给定 n 个实数,求这n个实数在数轴上相邻2个数之间的最大差值,设计解最大间隙问题的线性时间算法。
- ORACLE确定当前记录和下一条记录之间的差值
- 给定一个无序数组,排序之后求相邻两数之间的最大差值
- 求Maximim Gap 排序后的两个相邻元素之间的最大差值
- 最大间隙问题。给定 n 个实数,求这n个实数在数轴上相邻2个数之间的最大差值,设计解最大间隙问题的线性时间算法。
- ORACLE确定当前记录和下一条记录之间的差值
- Mysql 相邻两行记录某列的差值方法
- oracle 根据时间排序,删除相邻的除排序字段均相同的两条中较新的一条记录
- sql利用rownum求相邻记录差值
- 有一个int型数组,每两个相邻的数之间的差值不是1就是-1.现在给定一个数,要求查找这个数在数组中的位置
- 【算法题】求有序数列中相邻数字之间的最大差值
- SQLServer 分组查询相邻两条记录的时间差
- 处理出租车计价器数据,计算空驶时间,即相邻两条记录相减
- mysql 计算相邻两条记录的时间差
- SQLServer 分组查询相邻两条记录的时间差
- mysql查询(同一个表中相邻的两条记录进行运算)
- Mysql 相邻两行记录某列的差值