------解决方案-------------------- select
min(t.Column1)Column1,
max(t.Column1)Column2
from(
select Column1,cnt=Column1-row_number()over(order by getdate()) from tb
)t group by cnt
--没测试 ------解决方案-------------------- select a.Num as Column1
(select top 1 b.num from test b
where b.num >= a.Num
and not exists (
select 1 from test
where Num = b.Num + 1
)
order by b.num asc
) as Column2
from test a
where not exists (
select 1 from test
where Num = a.Num - 1
)
order by 1 asc
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2013-10-17 11:32:39
-- Verstion:
-- Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
-- Feb 10 2012 19:39:15
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([Num] int)
insert [tb]