How can I find duplicate consecutive values in this table?

后端 未结 3 460
旧巷少年郎
旧巷少年郎 2020-12-16 03:52

Say I have a table which I query like so:

select date, value from mytable order by date

and this gives me results:

date             


        
3条回答
  •  自闭症患者
    2020-12-16 04:39

    This is a simplified version of @Bob Jarvis' answer, the main difference being the use of just one subquery instead of four,

    with f as (select row_number() over(order by d) rn, d, v from t3)
    select
      a.d, a.v,
      case when a.v in (prev.v, next.v) then '*' end match
    from
      f a
        left join
      f prev
        on a.rn = prev.rn + 1
        left join
      f next
        on a.rn = next.rn - 1
    order by a.d
    ;
    

提交回复
热议问题