示例如下,表A:
订单号 客户
263663 A
273631 A
163263 B
173636 B
想得到这样的结果:
客户 订单号
A 263663;273631
B 163263;173636
请问这个要怎么样才做得到呢,请各位高手赐教。
------解决方案--------------------
你也有够懒得了,我的不是中文系统,没法用中文,你看懂意思就自己试下阿。。。
SELECT
distinct 客户
, ltrim(first_value(a) over (partition by 客户 order BY lev DESC) , '; ') 订单号
FROM
(SELECT
客户
, 订单号
, LEVEL lev
, sys_connect_by_path(订单号, '; ') a
FROM
(SELECT
temp5.客户||ROWNUM c
, (temp5.客户 ||( ROWNUM - 1)) p
, 客户
, 订单号
FROM
temp5)
CONNECT BY
PRIOR c = p)
------解决方案--------------------
drop table invoice ;
create table invoice(order_num number(6),customer varchar2(20));
insert into invoice values (263663, 'A ');
insert into invoice values (273631, 'A ');
insert into invoice values (163263, 'B ');
insert into invoice values (173636, 'B ');
select customer,order_num from invoice;
SELECT
distinct customer,
ltrim(first_value(a) over (partition by customer order BY lev DESC) , '; ') order_num
FROM
(SELECT
customer,
order_num,
LEVEL lev,
sys_connect_by_path(order_num, '; ') a
FROM
(SELECT
invoice.customer||ROWNUM c,
(invoice.customer ||( ROWNUM - 1)) p,
customer,
order_num
FROM
invoice)
CONNECT BY
PRIOR c = p)