MsSQL   发布时间:2022-05-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了一道有趣的题目 转F大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
 

请教各位:
数据记录是这样的
1
2
3
4
5
12
17
18
19
20
25
请问sqlserver2000如何显示成这样1-5,12,17-20,25

 

declare @t table(num int)
insert into @t SELEct 1
union all SELEct 2
union all SELEct 3
union all SELEct 4
union all SELEct 5
union all SELEct 12
union all SELEct 17
union all SELEct 18
union all SELEct 19
union all SELEct 20
union all SELEct 25

SELEct
   
rtrim(a.num)+(case when @H_513_236@min(b.num)!=a.num then '-'+rtrim(@H_513_236@min(b.num)) else '' end)
from
    (
SELEct t.num from @t t where not exists(SELEct 1 from @t where num=t.num-1)) a,
    (
SELEct t.num from @t t where not exists(SELEct 1 from @t where num=t.num+1)) b
where
    a.num
<=b.num
group by a.num /*
-------------------------
1-5
12
17-20
25
*/  

大佬总结

以上是大佬教程为你收集整理的一道有趣的题目 转F全部内容,希望文章能够帮你解决一道有趣的题目 转F所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:1217-20