oracle如何去列的重复,oracle重复列只显示一次的实现

CREATE

TABLE test(

ob_id

VARCHAR(32),

ob_name

VARCHAR(32)

);

INSERT

INTO test VALUES('A001','A001-a');

INSERT

INTO test VALUES('A001','A001-b');

INSERT

INTO test VALUES('A001','A001-c');

INSERT

INTO test VALUES('A001','A001-d');

INSERT

INTO test VALUES('A002','A002-a');

INSERT

INTO test VALUES('A002','A002-b');

INSERT

INTO test VALUES('A002','A002-c');

INSERT

INTO test VALUES('A002','A002-d');

COMMIT;

查询结果:

OB_ID

OB_NAME

A001

A001-a

A001

A001-b

A001

A001-c

A001

A001-d

A002

A002-a

A002

A002-b

A002

A002-c

A002

A002-d

如何实现下面的查询结果:

OB_ID

OB_NAME

A001

A001-a

A001-b

A001-c

A001-d

A002A002-a

A002-b

A002-c

A002-d

方法一:

select

decode(rownum,1,ob_id,5,ob_id) ob_id,ob_name from test;

方法二:

select

decode(row_number() over(partition by ob_id order by

ob_name),1,ob_id) ob_id,ob_name from test t;

方法三:

select

decode(lag(ob_id) over(partition by ob_id order by ob_name), ob_id,

null, ob_name) ob_id,ob_name from test;

方法四:

SELECT

CASE WHEN m.rn=m.rn1 THEN NULL ELSE m.ob_id END ob_id,

m.ob_name

FROM

(SELECT

d.ob_id,d.ob_name,rn,LAG(d.rn) OVER(ORDER BY d.ob_id) rn1

FROM

(SELECT

t.ob_id,t.ob_name,dense_RANK() OVER( ORDER BY t.ob_id) rn

FROM TEST

t) d) m;

方法五:

select

decode(t1.ob_name, v.name, t1.ob_id, ''), t1.ob_name

from (select * from test t where rowid in (select min(rowid) from

test group

by ob_id,ob_name)) t1

join (select t.ob_id id, min(t.ob_name) name from test t group by

t.ob_id) v on v.id = t1.ob_id

order by

t1.ob_id, t1.ob_name;

方法六:

在sqlplus中

break on

ob_id skip

select *

from test;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值