数据如下:pid x y uid tim
----------- ----------------------- ----------------------------------------------------- -----
1 41.759292000000002 123.49645599999999 1 2010-08-06 16:49:20.000
2 61.759292000000002 123.49645599999999 2 2010-08-06 16:49:51.000
3 63.759292000000002 123.49645599999999 2 2010-08-06 16:50:21.000
4 41.759292000000002 123.49645599999999 1 2010-08-06 16:50:52.000
5 41.759292000000002 123.49645599999999 1 2010-08-06 16:51:22.000
6 41.759292000000002 123.49645599999999 1 2010-08-06 16:51:53.000
7 65.759292000000002 123.49645599999999 2 2010-08-06 16:52:23.000
8 41.759292000000002 123.49645599999999 1 2010-08-06 16:52:54.000
9 41.759292000000002 123.49645599999999 1 2010-08-06 16:53:25.000
10 41.759292000000002 123.49645599999999 1 2010-08-06 16:54:39.000我想查询uid等于1的数据。并且可以根据时间间隔来查询数据的 如间隔1秒 间隔3秒等等。现在我遇到的情况是我可以取出
记录但是是随机的而不是可设置的。请大家帮帮忙,十分感谢
----------- ----------------------- ----------------------------------------------------- -----
1 41.759292000000002 123.49645599999999 1 2010-08-06 16:49:20.000
2 61.759292000000002 123.49645599999999 2 2010-08-06 16:49:51.000
3 63.759292000000002 123.49645599999999 2 2010-08-06 16:50:21.000
4 41.759292000000002 123.49645599999999 1 2010-08-06 16:50:52.000
5 41.759292000000002 123.49645599999999 1 2010-08-06 16:51:22.000
6 41.759292000000002 123.49645599999999 1 2010-08-06 16:51:53.000
7 65.759292000000002 123.49645599999999 2 2010-08-06 16:52:23.000
8 41.759292000000002 123.49645599999999 1 2010-08-06 16:52:54.000
9 41.759292000000002 123.49645599999999 1 2010-08-06 16:53:25.000
10 41.759292000000002 123.49645599999999 1 2010-08-06 16:54:39.000我想查询uid等于1的数据。并且可以根据时间间隔来查询数据的 如间隔1秒 间隔3秒等等。现在我遇到的情况是我可以取出
记录但是是随机的而不是可设置的。请大家帮帮忙,十分感谢
[Author]: OrchidCat[OC]_轻骑兵(向高手学习...)
[Time]: 2010-08-13 09:50:53
[Place]: From Beijing
[Version]:
Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86)
Feb 9 2007 22:47:07
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)*/
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([pid] int,[x] numeric(17,15),[y] numeric(17,14),[uid] int,[tim] datetime)
insert [TB]
select 1,41.759292000000002,123.49645599999999,1,'2010-08-06 16:49:20.000' union all
select 2,61.759292000000002,123.49645599999999,2,'2010-08-06 16:49:51.000' union all
select 3,63.759292000000002,123.49645599999999,2,'2010-08-06 16:50:21.000' union all
select 4,41.759292000000002,123.49645599999999,1,'2010-08-06 16:50:52.000' union all
select 5,41.759292000000002,123.49645599999999,1,'2010-08-06 16:51:22.000' union all
select 6,41.759292000000002,123.49645599999999,1,'2010-08-06 16:51:53.000' union all
select 7,65.759292000000002,123.49645599999999,2,'2010-08-06 16:52:23.000' union all
select 8,41.759292000000002,123.49645599999999,1,'2010-08-06 16:52:54.000' union all
select 9,41.759292000000002,123.49645599999999,1,'2010-08-06 16:53:25.000' union all
select 10,41.759292000000002,123.49645599999999,1,'2010-08-06 16:54:39.000'select * from [TB]
SELECT *,[间隔]=ABS(DATEDIFF(ss,(SELECT min(tim) FROM tb WHERE tim >A.tim AND uid =1 ),tim))
FROM TB A
WHERE A.uid = 1
不知道是不是这样子....
FROM TB A
WHERE A.uid = 1
/*
pid x y uid tim 间隔
----------- --------------------------------------- --------------------------------------- ----------- ----------------------- -----------
1 41.759292000000002 123.49645599999999 1 2010-08-06 16:49:20.000 92
4 41.759292000000002 123.49645599999999 1 2010-08-06 16:50:52.000 30
5 41.759292000000002 123.49645599999999 1 2010-08-06 16:51:22.000 31
6 41.759292000000002 123.49645599999999 1 2010-08-06 16:51:53.000 61
8 41.759292000000002 123.49645599999999 1 2010-08-06 16:52:54.000 31
9 41.759292000000002 123.49645599999999 1 2010-08-06 16:53:25.000 74
10 41.759292000000002 123.49645599999999 1 2010-08-06 16:54:39.000 0(7 行受影响)*/
[Author]: OrchidCat[OC]_轻骑兵(向高手学习...)
[Time]: 2010-08-13 09:50:53
[Place]: From Beijing
[Version]:
Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86)
Feb 9 2007 22:47:07
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)*/
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([pid] int,[x] numeric(17,15),[y] numeric(17,14),[uid] int,[tim] datetime)
insert [TB]
select 1,41.759292000000002,123.49645599999999,1,'2010-08-06 16:49:20.000' union all
select 2,61.759292000000002,123.49645599999999,2,'2010-08-06 16:49:51.000' union all
select 3,63.759292000000002,123.49645599999999,2,'2010-08-06 16:50:21.000' union all
select 4,41.759292000000002,123.49645599999999,1,'2010-08-06 16:50:52.000' union all
select 5,41.759292000000002,123.49645599999999,1,'2010-08-06 16:51:22.000' union all
select 6,41.759292000000002,123.49645599999999,1,'2010-08-06 16:51:53.000' union all
select 7,65.759292000000002,123.49645599999999,2,'2010-08-06 16:52:23.000' union all
select 8,41.759292000000002,123.49645599999999,1,'2010-08-06 16:52:54.000' union all
select 9,41.759292000000002,123.49645599999999,1,'2010-08-06 16:53:25.000' union all
select 10,41.759292000000002,123.49645599999999,1,'2010-08-06 16:54:39.000'select * from [TB]
SELECT *,[间隔]=ABS(DATEDIFF(ss,(SELECT min(tim) FROM tb WHERE tim >A.tim AND uid =1 ),tim))
FROM TB A
WHERE A.uid = 1
不知道是不是这样子....