随笔-2  评论-0  文章-0  trackbacks-0

筛选连续数据

create table test
(
[min] int,
[max] int
)

insert into test select 1,     5
insert into test select 6,     10
insert into test select 11,    15
insert into test select 20,    30
insert into test select 40,    50
insert into test select 51,    60


--语句
select [min],[max] = (select min([max]) from test t1
where [max]>t2.[min] and not exists(select 1 from test where [min] = t1.[max]+1)
)
from test t2
where not exists(select 1 from test where [max] = t2.[min]-1)

--结果
1 15
20 30
40 60

posted on 2007-03-20 17:17 冷箫轻笛 阅读(24) 评论(0) 编辑 收藏
昵称:冷箫轻笛
园龄:5年4个月
粉丝:0
关注:0
<2007年3月>
25262728123
45678910
11121314151617
18192021222324
25262728293031
1234567

搜索

 
 

最新随笔

随笔分类

随笔档案

精彩Blog

最新评论