怎样过滤连续重复的数据呢?
ID 经度 纬度
1 116.1 36.1
2 116.2 36.1
3 116.2 36.1
4 116.2 36.1
5 116.3 36.1
6 116.2 36.1
我想要他出来
1 116.1 36.1
2 116.2 36.1
5 116.3 36.1
6 116.2 36.1
[解决办法]
select min(id) id,经度,纬度from tbgroup by 经度,纬度
[解决办法]
0.0 我看错了,1楼不行。
;with ach as( select *,rid=row_number() over (order by getdate()), pid=row_number() over (partition by 经度,纬度 order by id) from tb)select *from ach twhere not exists (select 1 from ach where rid-pid=t.rid-t.pid and id < t.id)
[解决办法]
--> 测试数据:[TBL]goif object_id('[TBL]') is not null drop table [TBL]gocreate table [TBL]([ID] int,[经度] numeric(4,1),[纬度] numeric(3,1))goinsert [TBL]select 1,116.1,36.1 union allselect 2,116.2,36.1 union allselect 3,116.2,36.1 union allselect 4,116.2,36.1 union allselect 5,116.3,36.1 union allselect 6,116.2,36.1;WITH TAS(SELECT *,ROW_NUMBER()OVER(ORDER BY GETDATE()) AS NUM,ROW_NUMBER()OVER(PARTITION BY [经度],[纬度] ORDER BY [ID] ) AS [ORDER]FROM [TBL])SELECT [ID],[经度],[纬度] FROM T WHERE [ORDER]=1UNIONSELECT [ID],[经度],[纬度] FROM T WHERE ID-[ORDER]<>1/*ID 经度 纬度1 116.1 36.12 116.2 36.15 116.3 36.16 116.2 36.1*/