找出连续/不连续的记录?

bz586 2007-02-08 11:56:08
表格如下:
id num
1 0
2 0
3 1
4 1
5 1
6 1
7 0
8 1
9 1
10 0
.. ..
希望得到如下的结果集:
3 1
8 1

还有

7 0
10 0
...全文
184 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunqiso 2008-09-29
  • 打赏
  • 举报
回复

wangdehao 2007-02-08
  • 打赏
  • 举报
回复
select * from tb a where exists(select * from tb where id=a.id-1 and num<>a.num)--?
撸大湿 2007-02-08
  • 打赏
  • 举报
回复
给算法
yangjianw2004 2007-02-08
  • 打赏
  • 举报
回复
create table test(id int,num varchar(10))
insert into test
select 1,'0'
union all select 2,'0'
union all select 3,'1'
union all select 4,'1'
union all select 5,'1'
union all select 6,'1'
union all select 7,'0'
union all select 8,'1'
union all select 9,'1'
union all select 10,'0'

select * from test A where exists(select * from test where id=A.id-1 and num<>A.num);
-------------------------------------------------------------------------------------
3 1
7 0
8 1
10 0

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧