/*
sql去除连续重复值
描述:有如下表
-----------------idname muser
1 n1 u1
2 n1 u2
3 n1 u3
4 n2 u4
5 n1 u5
-----------------
要求:去除表中连续重复的 name 值,输出如下结果:
-----------------idname muser
1 n1 u1
4 n2 u4
5 n1 u5
-----------------
解决办法:
*/
with x as(
select 1asid, 'n1' asname, 'u1' as muser from dual union all
select 2asid, 'n1' asname, 'u2' as muser from dual union all
select 3asid, 'n1' asname, 'u2' as muser from dual union all
select 4asid, 'n2' asname, 'u3' as muser from dual union all
select 5asid, 'n1' asname, 'u4' as muser from dual
)
select * from x c wherenot exists(
select b.idfrom x a, x b
where b.id = a.id+1and b.name = a.nameand c.id = b.id
)
order by c.id