ITPub博客

首页 > 数据库 > 数据库开发技术 > 断号查询问题

断号查询问题

原创 数据库开发技术 作者:Steven1981 时间:2007-09-29 14:39:15 0 删除 编辑

看书而得

[@more@]

SQL> select * from hyf_t1 order by id
2 ;

ID
-------
100
101
102
103
104
106
107
108
109
112
113
114
117
118

14 rows selected

SQL>
SQL> select * from (select id+1 begin,
2 sum( id) over(order by id rows between 0 preceding and 1 following) - id-1

end
3 ,sum( id) over(order by id rows between 0 preceding and 1 following) - id-

id-1 bb
4 from hyf_t1 ) where bb>0
5 /

BEGIN END BB
---------- ---------- ----------
105 105 1
110 111 2
115 116 2

这样也行:
SQL> select * from (
2 select id+1 begin ,
3 lead(id,1,0) over(order by id )-1 end,
4 lead(id,1,0) over(order by id )- id-1 bb
5 from hyf_t1 ) where bb>0
6 /

BEGIN END BB
---------- ---------- ----------
105 105 1
110 111 2
115 116 2

SQL>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/703656/viewspace-973987/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oracle分析函数-6
请登录后发表评论 登录
全部评论
  • 博文量
    127
  • 访问量
    855003