ITPub博客

首页 > 数据库 > 数据库开发技术 > 这样的SQL能够实现吗?

这样的SQL能够实现吗?

原创 数据库开发技术 作者:freeka 时间:2007-02-16 19:32:06 0 删除 编辑
create table t01(col1 number);
inser into t01 vaues(1):
inser into t01 vaues(2):
inser into t01 vaues(3):
inser into t01 vaues(6):
inser into t01 vaues(7):
inser into t01 vaues(9):
inser into t01 vaues(10):

需查询结果:
min max count
------------------------
1 3 3
6 7 2
9 10 2

即统计连号数[@more@]

select min(col1), max(col1),count(*)
from (select col1,col1 - row_number() over (order by col1) rn from t01)
group by rn;

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

上一篇: Worm.Win32.Delf.aj
请登录后发表评论 登录
全部评论
  • 博文量
    55
  • 访问量
    24331