ID 缴费号码    缴费金额
1   139139134    60
2   139139139    50
3   139139134    40
4   139139134    50
5   139139139    70   
6   139139134    80
现在需要SQL找出 可能不止2次
3   139139134    40
4   139139134    50

解决方案 »

  1.   


    with aa as

      select id,no,fee,
      count(1) over (
                     patition by no,order by id
                     rows between unbounded preceding and unbounded following                 
                     ) pay_times
    from t
    )
    select *
    from aa
    where pay_times>1
      

  2.   

    不好意思 没看到连续两个字wiht aa as
    (
    select t.id,t.no,t.fee,
            lag(no,1,no) over(order by id) last_no,
            lead(no,1,no) over(order by id) next_no
    from t
    )
    select * from aa where no=last_no or no=next_no
      

  3.   

    这样写默认值第一行和最后一行会出错
    wiht aa as
    (
    select t.id,t.no,t.fee,
            lag(no,1,null) over(order by id) last_no,
            lead(no,1,null) over(order by id) next_no
    from t
    )
    select * from aa where no=last_no or no=next_no
      

  4.   

    取上一行
    取下一行
    plsql特有的
      

  5.   

    select t1.* from table t1,(select t.缴费号码 num1 from table t group by t.缴费号码 having(count(1)>1)) where t1.缴费号码=num1 order by 缴费号码;