选手坐标表: select '选手1' 编号, 时刻1 检测时间, 0 x坐标 ,0 y坐标 into #
insert into # select '选手1' , '时刻2' , 10 , 10
insert into # select '选手1' , '时刻3' , 20 , 20
insert into # select '选手1' , '时刻4' , 30 , 30
insert into # select '选手1' , '时刻5' , 20 , 20
insert into # select '选手1' , '时刻6' , 40 , 60
insert into # select '选手3' , '时刻1' , 10 , 10
insert into # select '选手3' , '时刻2' , 10 , 10
insert into # select '选手3' , '时刻3' , 20 , 20
insert into # select '选手3' , '时刻4' , 30 , 30
insert into # select '选手3' , '时刻5' , 40 , 40
insert into # select '选手3' , '时刻6' , 20 , 20
insert into # select '选手3' , '时刻7' , 9 , 10
删除规则说明:
1.判断每个选手时刻2与时刻1的距离,若距离小于20,则删除时刻2的数据
编号 检测时间 x坐标 y坐标
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻4 30 30
选手1 时刻5 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻3 20 20
选手3 时刻4 30 30
选手3 时刻5 601 80
选手3 时刻6 9 9
2.判断每个选手时刻3与上一个有效时刻的距离,若距离小于20,则删除时刻3的数据
编号 检测时间 x坐标 y坐标
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻4 30 30
选手1 时刻5 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻4 30 30
选手3 时刻5 601 80
选手3 时刻6 9 9
3.判断每个选手时刻4与上一个有效时刻的距离,若距离小于20,则删除时刻4的数据
编号 检测时间 x坐标 y坐标
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻5 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻4 30 30
选手3 时刻5 601 80
选手3 时刻6 9 9 *********按该算法删除所有误差数据**************得出输出结果,并分组编号为:
编号 检测时间 x坐标 y坐标 分组序号
选手1 时刻1 0 0 1
选手1 时刻3 20 20 2
选手1 时刻6 40 60 3
选手3 时刻1 10 10 1
选手3 时刻4 30 30 2
选手3 时刻7 9 10 3
数据量较大,不考虑用游标
insert into # select '选手1' , '时刻2' , 10 , 10
insert into # select '选手1' , '时刻3' , 20 , 20
insert into # select '选手1' , '时刻4' , 30 , 30
insert into # select '选手1' , '时刻5' , 20 , 20
insert into # select '选手1' , '时刻6' , 40 , 60
insert into # select '选手3' , '时刻1' , 10 , 10
insert into # select '选手3' , '时刻2' , 10 , 10
insert into # select '选手3' , '时刻3' , 20 , 20
insert into # select '选手3' , '时刻4' , 30 , 30
insert into # select '选手3' , '时刻5' , 40 , 40
insert into # select '选手3' , '时刻6' , 20 , 20
insert into # select '选手3' , '时刻7' , 9 , 10
删除规则说明:
1.判断每个选手时刻2与时刻1的距离,若距离小于20,则删除时刻2的数据
编号 检测时间 x坐标 y坐标
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻4 30 30
选手1 时刻5 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻3 20 20
选手3 时刻4 30 30
选手3 时刻5 601 80
选手3 时刻6 9 9
2.判断每个选手时刻3与上一个有效时刻的距离,若距离小于20,则删除时刻3的数据
编号 检测时间 x坐标 y坐标
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻4 30 30
选手1 时刻5 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻4 30 30
选手3 时刻5 601 80
选手3 时刻6 9 9
3.判断每个选手时刻4与上一个有效时刻的距离,若距离小于20,则删除时刻4的数据
编号 检测时间 x坐标 y坐标
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻5 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻4 30 30
选手3 时刻5 601 80
选手3 时刻6 9 9 *********按该算法删除所有误差数据**************得出输出结果,并分组编号为:
编号 检测时间 x坐标 y坐标 分组序号
选手1 时刻1 0 0 1
选手1 时刻3 20 20 2
选手1 时刻6 40 60 3
选手3 时刻1 10 10 1
选手3 时刻4 30 30 2
选手3 时刻7 9 10 3
数据量较大,不考虑用游标
解决方案 »
- 有没有跟校内开心一样的学校和城市数据库
- 求教一查询语句
- 一个SQL SERVER 2000的BUG
- 大容量数据读写分离方案讨论
- SQL怎样将旧表导入新表中
- 我这句子何错?[code=SQL]select SmID from 面积计算图R WHERE Q房号='602' and Q所在层 == 'D'[/code]
- *******游标游标真是难啊,对游标有一定了解的朋友们,来谈谈你的看法
- 退出windows如何将正在运行的VFP程序关闭?
- 接近行转列问题,但是又不是,如何写这个循环,在sql server2008中
- 错误语法“create rule"必须是批处理中仅有的语句,怎么修改
- 请高手帮帮忙
- sql的四舍五入 函数是什么
IF OBJECT_ID( 'tempdb..#') IS NOT NULL
DROP TABLE #
go
IF OBJECT_ID( 'tempdb..#1') IS NOT NULL
DROP TABLE #1
go
select '选手1' 编号, '时刻1' 检测时间, 0 x坐标 ,0 y坐标 into #
union all select '选手1' , '时刻2' , 10 , 10
union all select '选手1' , '时刻3' , 20 , 20
union all select '选手1' , '时刻4' , 30 , 30
union all select '选手1' , '时刻5' , 20 , 20
union all select '选手1' , '时刻6' , 40 , 60
union all select '选手3' , '时刻1' , 10 , 10
union all select '选手3' , '时刻2' , 10 , 10
union all select '选手3' , '时刻3' , 20 , 20
union all select '选手3' , '时刻4' , 30 , 30
union all select '选手3' , '时刻5' , 40 , 40
union all select '选手3' , '时刻6' , 20 , 20
union all select '选手3' , '时刻7' , 9 , 10 SELECT a.编号,a.检测时间,MIN(a.x坐标) x坐标,MIN(a.y坐标) y坐标 ,MIN(b.检测时间 ) n检测时间
INTO #1
FROM # a
LEFT JOIN # b
ON a.编号 = b.编号 AND a.检测时间 < b.检测时间 AND (b.x坐标-a.x坐标)*(b.x坐标-a.x坐标)+(b.y坐标 -a.y坐标 )*(b.y坐标 -a.y坐标 )>= 400
GROUP BY a.编号,a.检测时间
ORDER BY a.编号,a.检测时间
/*
SELECT * FROM #1 a
WHERE a.检测时间 IN (SELECT n检测时间 FROM #1 WHERE a.编号 = 编号)
*/
ALTER TABLE #1 ADD flag INT
go
DECLARE @time1 AS VARCHAR(100)
DECLARE @time2 AS VARCHAR(100)
DECLARE @i INT
UPDATE #1 SET flag = @i--CASE WHEN @time1 = 检测时间 OR @time1 IS null THEN 1 ELSE 0 END
,@i = CASE WHEN @time1 = 检测时间 OR @time1 IS NULL THEN 1 ELSE 0 end
,@time1 = CASE WHEN @time1 = 检测时间 OR @time1 IS NULL THEN n检测时间 ELSE @time1 end
SELECT 编号,检测时间,x坐标,y坐标 FROM #1
WHERE flag = 1编号 检测时间 x坐标 y坐标
----- ----- ----------- -----------
选手1 时刻1 0 0
选手1 时刻3 20 20
选手1 时刻6 40 60
选手3 时刻1 10 10
选手3 时刻4 30 30
选手3 时刻7 9 10(所影响的行数为 6 行)
IF OBJECT_ID( 'tempdb..#') IS NOT NULL
DROP TABLE #
go
IF OBJECT_ID( 'tempdb..#1') IS NOT NULL
DROP TABLE #1
go
select '选手1' 编号, '时刻1' 检测时间, 0 x坐标 ,0 y坐标 into #
union all select '选手1' , '时刻2' , 10 , 10
union all select '选手1' , '时刻3' , 20 , 20
union all select '选手1' , '时刻4' , 30 , 30
union all select '选手1' , '时刻5' , 20 , 20
union all select '选手1' , '时刻6' , 40 , 60
union all select '选手1' , '时刻7' , 40 , 60
union all select '选手3' , '时刻1' , 10 , 10
union all select '选手3' , '时刻2' , 10 , 10
union all select '选手3' , '时刻3' , 20 , 20
union all select '选手3' , '时刻4' , 30 , 30
union all select '选手3' , '时刻5' , 40 , 40
union all select '选手3' , '时刻6' , 20 , 20
union all select '选手3' , '时刻7' , 9 , 10
union all select '选手3' , '时刻8' , 9 , 10 按楼上的,如果多加两行,结果不对
IF OBJECT_ID( 'tempdb..#') IS NOT NULL
DROP TABLE #
go
IF OBJECT_ID( 'tempdb..#1') IS NOT NULL
DROP TABLE #1
go
select '选手1' 编号, '时刻1' 检测时间, 0 x坐标 ,0 y坐标 into #
union all select '选手1' , '时刻2' , 10 , 10
union all select '选手1' , '时刻3' , 20 , 20
union all select '选手1' , '时刻4' , 30 , 30
union all select '选手1' , '时刻5' , 20 , 20
union all select '选手1' , '时刻6' , 40 , 60
union all select '选手1' , '时刻7' , 40 , 60
union all select '选手3' , '时刻1' , 10 , 10
union all select '选手3' , '时刻2' , 10 , 10
union all select '选手3' , '时刻3' , 20 , 20
union all select '选手3' , '时刻4' , 30 , 30
union all select '选手3' , '时刻5' , 40 , 40
union all select '选手3' , '时刻6' , 20 , 20
union all select '选手3' , '时刻7' , 9 , 10
union all select '选手3' , '时刻8' , 9 , 10 select *,ROW_NUMBER ()over(partition by 编号 order by 检测时间)sn
into #1
from #;with tb(player,CheckTime,Xco,Yco,SN,IsKeeped,X1,Y1)
AS
(SELECT 编号,检测时间,x坐标,y坐标,SN,1,x坐标,y坐标 FROM #1
WHERE SN=1UNION ALL
SELECT 编号,检测时间,x坐标,y坐标,a.SN,
case when (x坐标-X1)*(x坐标-X1) +(y坐标-Y1 )*(y坐标-Y1 )>400 then 1 else 0 end
,case when (x坐标-X1)*(x坐标-X1) +(y坐标-Y1 )*(y坐标-Y1 )>400 then x坐标 else x1 end
,case when (x坐标-X1)*(x坐标-X1) +(y坐标-Y1 )*(y坐标-Y1 )>400 then y坐标 else y1 end
FROM #1 A
JOIN tb b on a.编号=b.player and a.sn=b.SN+1
)
select player ,CheckTime ,Xco ,Yco from tb where IsKeeped =1
;with t1 as(
select 编号,检测时间,x坐标,y坐标 FROM # WHERE 检测时间 in('时刻1','时刻2')
),t2 as(
select 编号,'时刻2' 检测时间,x坐标,y坐标,
(select x坐标 from t1 a where a.编号=b.编号 and a.检测时间='时刻1') x1坐标,
(select y坐标 from t1 a where a.编号=b.编号 and a.检测时间='时刻1') y1坐标
from t1 b where 检测时间='时刻2'
),t3 as (
select 编号,'时刻2' 检测时间,x坐标,y坐标 from t2 where (x坐标+y坐标-x1坐标-y1坐标)<=20
)
delete from # from # a inner join t3 b on a.编号=b.编号 and a.检测时间=b.检测时间
/*
(2 行受影响)*/
;with t1 as(
select row_number() over(partition by 编号 order by cast(replace(检测时间,'时刻','') as int)) cnt,* from #
),t2 as(
select * from t1 where 检测时间='时刻3'
),t3 as(
select a.* from t1 a inner join t2 b on a.编号=b.编号 and (a.cnt=b.cnt or a.cnt+1=b.cnt)
),t4 as(
select 编号,'时刻3' 检测时间,x坐标,y坐标,
(select x坐标 from t3 a where a.编号=b.编号 and a.cnt+1=b.cnt) x1坐标,
(select y坐标 from t3 a where a.编号=b.编号 and a.cnt+1=b.cnt) y1坐标
from t3 b where 检测时间='时刻3'
)
delete from # from # a inner join t4 b on a.编号=b.编号 and a.检测时间=b.检测时间
/*
(2 行受影响)
*/
;with t1 as(
select row_number() over(partition by 编号 order by cast(replace(检测时间,'时刻','') as int)) cnt,* from #
),t2 as(
select * from t1 where 检测时间='时刻3'
),t3 as(
select a.* from t1 a inner join t2 b on a.编号=b.编号 and (a.cnt=b.cnt or a.cnt+1=b.cnt)
),t4 as(
select 编号,'时刻3' 检测时间,x坐标,y坐标,
(select x坐标 from t3 a where a.编号=b.编号 and a.cnt+1=b.cnt) x1坐标,
(select y坐标 from t3 a where a.编号=b.编号 and a.cnt+1=b.cnt) y1坐标
from t3 b where 检测时间='时刻3'
),t5 as (
select 编号,'时刻3' 检测时间,x坐标,y坐标 from t4 where (x坐标+y坐标-x1坐标-y1坐标)<=20
)
delete from # from # a inner join t5 b on a.编号=b.编号 and a.检测时间=b.检测时间
/*
(1 行受影响)
*/
要更改SQL SERVER 设置
100是默认设置