表A,两个字段t1,t2
t1   t2
3    2
4    3
5    1
6    2
7    3
要求查询得到,t1-t2的值连续>=3的次数。

解决方案 »

  1.   

    根据表数值得到t1-t2的值为
    1
    1
    4
    4
    4
    得到t1-t2的值>=3的次数为3次。
      

  2.   

    这样吧,查询t1-t2的值>=3连续二次以上的次数
      

  3.   

    可以用分析函数lag(clo1,col2,col3)--按分组排序号,对数据再一次进行检索,clo1和clo3都是返回值
    试一下
      

  4.   

    select a2
    from(select t1-t2 a1,sum(decode(sign(t1-t2-3),-1,0,1)) a2 from a
    group by t1-t2)
    where a2>=2
      

  5.   

    select count(1) from a where (t1-t2)>=3