当前位置: 代码迷 >> Oracle开发 >> sql 查寻某列连续的几个值是否相同
  详细解决方案

sql 查寻某列连续的几个值是否相同

热度:6   发布时间:2016-04-24 06:57:48.0
sql 查找某列连续的几个值是否相同
我有一个table类似下面

name  item  value  rectime
A     001   0.98   2013/7/24 12:12:30
A     002   0.98   2013/7/23 09:06:50
A     002   0.95   2013/7/23 08:00:00
B     004   0.95   2013/7/24 10:10:30
B     002   0.95   2013/7/24 03:05:00
C     005   0.95   2013/7/24 12:12:30

我想实现 group by name ,order by rectime desc

找出是否有 3个连续的value相同

------解决方案--------------------
引用:
Quote: 引用:

是求出有三个连续的value相同的name吗?
with
t as (select 'A' name,001 item,0.98 value,to_date('2013/7/24 12:12:30','yyyy/mm/dd hh24:mi:ss')rectime from dual
     union all 
     select 'A' name,002 item,0.98 value,to_date('2013/7/23 09:06:50','yyyy/mm/dd hh24:mi:ss')rectime from dual
     union all 
     select 'A' name,002 item,0.98 value,to_date('2013/7/23 08:00:00','yyyy/mm/dd hh24:mi:ss')rectime from dual
     union all 
     select 'B' name,004 item,0.95 value,to_date('2013/7/24 10:10:30','yyyy/mm/dd hh24:mi:ss')rectime from dual
     union all 
     select 'B' name,002 item,0.95 value,to_date('2013/7/24 03:05:00','yyyy/mm/dd hh24:mi:ss')rectime from dual
     union all 
     select 'C' name,005 item,0.95 value,to_date('2013/7/24 12:12:30','yyyy/mm/dd hh24:mi:ss')rectime from dual)
select distinct t1.name 
from (select t.*,lag(value)over(partition by name order by rectime desc)lag_value,
  相关解决方案