create table test (id int, c_no int, c_num int);insert into test select 1,10001,20 from dual; 
insert into test select 2,10001,30 from dual; 
insert into test select 3,10001,40 from dual; 
insert into test select 4,10001,100 from dual; 
insert into test select 5,10001,20 from dual; 
insert into test select 6,10001,40 from dual; 
insert into test select 7,10001,30 from dual; 
insert into test select 8,10001,50 from dual; commit;需求:id从1开始排序,取c_num小于等于60的数据,如下:
---------
1,10001,20
2,10001,30
3,10001,40
求高手帮忙,很急!

解决方案 »

  1.   

    select * from test t where t.c_num <= 60 order by t.id 
    这样行吗?
      

  2.   

    可能没理解我的意思,我其实只要取下面的数据:
    1,10001,20
    2,10001,30
    3,10001,40下面的我是不需要的
    4,10001,100
    5,10001,20
    insert into test select 6,10001,40 
    insert into test select 7,10001,30
    insert into test select 8,10001,50
      

  3.   

    Quote: 引用 4 楼 et024 的回复:

    引用 3 楼 elhao2011 的回复:
    不好意思,上面写错了,下面是不需要的:
    4,10001,100
    5,10001,20
    6,10001,40 
    7,10001,30
    8,10001,50
      

  4.   

    with test1 as(
    select id,c_no,c_num,nvl(lag(c_num) over(order by id),10) c_num1 from test
    )
    select * from test1 where c_num=c_num1+10;
      

  5.   

    select id,c_no,c_num,nvl(lag(c_num) over(order by id),10) c_num1 from test
    可为
    select id,c_no,c_num,lag(c_num,1,10) over(order by id) c_num1 from test
      

  6.   

    这个简单,用下面的SQL:
    select *
      from test t
     where t.c_num <= 60
       and id < (select min(id) from test t where t.c_num > 60);