sql去除连续重复值

sql去除连续重复值

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值