有两个字段
A     B
1     B-1
2     B-2
3     B-3
4     B-4
5     B-6
6     B-5
我现在想找出5,6这两条记录,本来A,B两个字段都是顺序增加,5,6记录乱了,我想找出这样的记录,请问这条sql应该怎么写? 

解决方案 »

  1.   

    select A,B from table_name
    where A!=substr(B,3);
      

  2.   

    二楼,我说的顺序增加不一定A,B是对应的
    A   B
    1   2
    2   4
    3   5
    4   7
    5   6
    也可能是这样
      

  3.   

    create table test
    (a varchar2(3),
     b varchar2(5)
    )
    1 2
    2 4
    3 5
    4 7
    5 6select * from (
      select t.a,t.b,
        lag(t.b)over( order by t.a asc) sq
      from test t)
    where  sq>b原理就是按照字段A排序取出上个序号的值,如果上个序号的值比当前序号的值大,那就是顺序有问题