日期:2011-01-25 23:11:00 来源:本站整理
利用SQL语句实现查询持续号段[MSSQL防范]
本文“利用SQL语句实现查询持续号段[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
下面将教您若何利用SQL语句实现查询持续号段,供您参考,假如您对SQL语句实现查询持续号段这个办法感爱好的话,无妨一看,对您学习SQL语句利用会有所帮忙.
- With tempTable As(
- select 2014 code,'00000001' tel from dual union all
- select 2014 code,'00000002' tel from dual union all
- select 2014 code,'00000003' tel from dual union all
- select 2014 code,'00000004' tel from dual union all
- select 2014 code,'00000005' tel from dual union all
- select 2014 code,'00000007' tel from dual union all
- select 2014 code,'00000008' tel from dual union all
- select 2014 code,'00000009' tel from dual union all
- select 2013 code,'00000120' tel from dual union all
- select 2013 code,'00000121' tel from dual union all
- select 2013 code,'00000122' tel from dual union all
- select 2013 code,'00000124' tel from dual union all
- select 2013 code,'00000125' tel from dual
- ),
- group_tempTable As(
- Select a.*, a.tel - Rownum 分组
- From (Select *
- From tempTable
- Order By code, tel) a
- )
- Select b.code, Min(b.tel) Start_Tel, Max(b.tel) End_Tel
- From group_tempTable b
- Group By b.code, b.分组
- Order By b.code, b.分组
履行后果:
<
- CODE START_TEL END_TEL
- 1 2013 00000120 00000122
- 2 2013 00000124 00000125
- 3 2014 00000001 00000005
- 4 2014 00000007 00000009
以上是“利用SQL语句实现查询持续号段[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论