满意答案
xyn313
2013.06.13
采纳率:58% 等级:12
已帮助:6549人
----测试数据CREATE TABLE HR.tablea
(
iid INT NOT NULL,
aname VARCHAR2(20) NOT NULL,
add1 VARCHAR2(100)
)
ALTER TABLE HR.tablea ADD (CONSTRAINT tablea_PK
PRIMARY KEY
(iid,aname));
insert into HR.TABLEA values (1,'张三','中国')
insert into HR.TABLEA values (2,'张三','中国')
insert into HR.TABLEA values (3,'张三','中国')
insert into HR.TABLEA values (4,'张三','中国')
insert into HR.TABLEA values (1,'李四','中国')
insert into HR.TABLEA values (2,'李四','中国')select * from hr.tablea ----查询语句
select t.*,
(
select max(sys_connect_by_path(iid, ', ')) result from
(select aname,iid,rn,lead(rn) over(partition by aname order by rn) rn1
from (select aname,iid,row_number() over(order by aname,iid desc) rn from hr.tablea)
)
start with aname = t.aname and rn1 is null connect by rn1 = prior rn
) value
from (select distinct aname,add1 from hr.tablea) t ----查询结果
00分享举报