sql 送分玩
tab
id
1
2
4
5
7
结果:
id
(3,6)
一条语句!嘿嘿!
------解决方案--------------------3,6怎么来的?
------解决方案--------------------我只接分,不答题,因为一条语句我答不出来
------解决方案--------------------3.6是跳号处理
------解决方案--------------------not in
------解决方案--------------------看看.
------解决方案--------------------再加個表
------解决方案--------------------select '(3,6) ' from tab;
------解决方案--------------------哈哈,开个玩笑.
------解决方案--------------------谢谢。我接分玩
------解决方案--------------------jf
------解决方案--------------------我也接分, :)
------解决方案--------------------select top 10 a=identity(int,1,1) into #test from sysobjects a,sysobjects b
declare @i int
select @i=max([id]) from dbo.tab
select test.a from #test as test left join dbo.tab on a=[id]
where a <=@i and [id] is null
------解决方案--------------------忘记drop table #test了
------解决方案--------------------lz的意思不明确,jf
------解决方案--------------------不懂,学习来了,帮顶吧,一条语句好象太难了,高人呢,来看看
你能给我一分就不错了,谢谢!
------解决方案--------------------Create table #tb (id int)
insert #tb(id)Values(1)
insert #tb(id)Values(2)
insert #tb(id)Values(4)
insert #tb(id)Values(5)
insert #tb(id)Values(7)
insert #tb(id)Values(9)
declare @str varchar(1000)
set @str= '( '
declare @int int
set @int=1
select @str=case when @int=id then @str else @str+convert(varchar,@int)+ ', ' end,
@int=@int+case when @int=id then 1 else 2 end
from #tb order by id
set @str=left(@str,len(@str)-1)+ ') '
print @str
drop table #tb
--执行结果
--(3,6,8)
------解决方案--------------------declare @tab table(id int)
insert into @tab select 1
insert into @tab select 2
insert into @tab select 4
insert into @tab select 5
insert into @tab select 7
select
case when (a.id+1)=min(b.id)-1 then rtrim(a.id+1) else rtrim(a.id+1)+ '- '+rtrim(min(b.id)-1) end as 断号区间
from
(select * from @tab m where not exists(select 1 from @tab where id=m.id+1)) a,
(select * from @tab m where not exists(select 1 from @tab where id=m.id-1)) b
where
a.id <b.id
group by
a.id
/*
断号区间
------------
3
6
*/
------解决方案--------------------declare @tab table(id int)
insert @tab select 1
union all select 2
union all select 4
union all select 5
union all select 7